These are chat archives for spring-cloud/spring-cloud

17th
Jan 2018
Fabian Wallwitz
@fabi2tweet_twitter
Jan 17 2018 06:43
Where to go for q/a around spring cloud data flow?
is here the right palce?
Dave Syer
@dsyer
Jan 17 2018 08:17
If you ping @sabbyanandan he shows up here to answer SCDF questions sometimes. He's asleep right now though, probably.
Jagmohan Sharma
@JagmohanSharma
Jan 17 2018 09:44
@dsyer Please find spring-cloud/spring-cloud-commons#308 ticket updated with github sample to reproduce the issue.
Jagmohan Sharma
@JagmohanSharma
Jan 17 2018 11:43
Here, bean registered using BDRPP is not getting refreshed on cloud config changes and this is not related to FactoryBean as I have tried without using FactoryBean now and still facing the issue. Now implementation is simply using a BDRPP to register a bean with refresh scope and autowires it into other components. Please have a look on github sample.
Jagmohan Sharma
@JagmohanSharma
Jan 17 2018 11:48
yes
Dave Syer
@dsyer
Jan 17 2018 11:51
It looks like a factory bean to me
Jagmohan Sharma
@JagmohanSharma
Jan 17 2018 12:07
actually I was talking about FactoryBean which we were previously making use for getting objects of certain type.
Currently we are explicitly setting scope as refresh bdb.setScope("refresh");, would not that be sufficient to make this bean refreshable?
Sorry for troubling you with confusing statement previously.
Dave Syer
@dsyer
Jan 17 2018 12:08
The bean that is in refresh scope is created by a factory bean
So it isn't itself refreshable
Apparently that's the way scoped proxies work
Jagmohan Sharma
@JagmohanSharma
Jan 17 2018 12:11
ok.
Jagmohan Sharma
@JagmohanSharma
Jan 17 2018 12:19
do you see any possible way to achieve bean refresh scope with same existing approach ?
Dave Syer
@dsyer
Jan 17 2018 12:20
I think I already suggested something?
Register a bean that isn't a factory and then a post processor
Jagmohan Sharma
@JagmohanSharma
Jan 17 2018 12:23
Yes. Thanks for your help. :)
Sabby Anandan
@sabbyanandan
Jan 17 2018 13:29
Hi, @fabi2tweet_twitter. Feel free to ping us at: https://gitter.im/spring-cloud/spring-cloud-stream
Viktor Gal
@vigsterkr
Jan 17 2018 15:39
hi! i'm trying to use spring-cloud-starter-zookeeper-config to configure beans via a zookeper. it works fine as long as i use it within a @RestController but as soon as i just want to use the beans values in my application for refreshing the bean's property i'm observing a weird - maybe that's a normal - behaviour. i.e. the values are not really refreshed :( they remain the same.... the way it was initialiazied when the application has started up and the values at that moment were in the ZK... when i put slf4j to debug mode i see all the RefreshEventListener events as well as the debug messages of currator, but the thread that is running in the original object to validate the value of the given class' mapped properties show no change in the values... any ideas? or probably i'm misinterpreting how this whole thing suppose to be working?
Dave Syer
@dsyer
Jan 17 2018 15:40
How do you mean "just want to use the beans values in my application"?
Do you have a simple sample?
Are you using @RefreshScope or @ConfigurationProperties, or both?
Viktor Gal
@vigsterkr
Jan 17 2018 15:41
@dsyer i'm using @RefresScope
Dave Syer
@dsyer
Jan 17 2018 15:41
A sample will help
Viktor Gal
@vigsterkr
Jan 17 2018 15:42
@dsyer note that the only moment i can observe a refresh in the @RestController's variables if i actually define a @GetMapping and do a get on that
ok lemme try to quickly put together something
but then if i do a get on that mapping i suddenly observe 2 instances of the same bean... one having the initial values... the second one having the new value
Dave Syer
@dsyer
Jan 17 2018 15:44
How do you "observe" that?
2 instances would be correct if you use @RefreshScope. One is the "before" and the other is the "after".
Viktor Gal
@vigsterkr
Jan 17 2018 15:45
i've just fire out a thread in the ctor of the bean that prints the properties in question of the given class
but that only gets refreshed
Dave Syer
@dsyer
Jan 17 2018 15:45
I think I need to see some code
Viktor Gal
@vigsterkr
Jan 17 2018 15:45
k
@dsyer as for the main i just have a Runner where in the main i do SpringApplication.run...
Dave Syer
@dsyer
Jan 17 2018 15:51
I can't really run that code yet
Can you put it in github?
Viktor Gal
@vigsterkr
Jan 17 2018 15:51
ah sure lemme put the whole thing
into a maven thingy
Dave Syer
@dsyer
Jan 17 2018 15:52
It looks to me like you are just going to see a load of logs in background threads. It won't tell you very much.
Your AppNoRefresh isn't a @Component so I don't see how @RefreshScope is going to get applied to it.
Need to see the whole project
Dave Syer
@dsyer
Jan 17 2018 16:09
Your AppNoRefresh is definitely not a @Component.
Viktor Gal
@vigsterkr
Jan 17 2018 16:10
adding @Component to it does not change the behaviour
Dave Syer
@dsyer
Jan 17 2018 16:10
I see you added it to the SpringApplication as a source, but it isn't annotated as a component, so you won't get a full bean lifecycle.
Viktor Gal
@vigsterkr
Jan 17 2018 16:10
and even in case of the AppRefreshes.... it only really refreshes when i initiate a http get on the /hello... and actually that constructs a brand new bean :(
i'd like to have a singleton if possible
i.e. the very same object :)
i mean i dont wanna use most part of spring - meaning http handler etc... but the whole configuration management of beans would be really nice to have
i'm just wondering whether the only way in this case if i wanna have a singleton is that actually @AutoWired a configuration class in my singleton and then spring will take care for me that the configuration object (having the @Value attribuites) will be always up to date?
Dave Syer
@dsyer
Jan 17 2018 16:16
The new instance is created when it is used
Your toy app is only calling methods internally
so the proxy is never accessed
I really definitely think you need to put @Component on your AppNoRefresh as well
Otherwise it won't even bind to the @Value will it?
It's all working as expected as far as I can tell
Viktor Gal
@vigsterkr
Jan 17 2018 16:34
@dsyer so if i have a singleton that i would like to have configured via a zk and have their values refreshable that i create say a configuration bean that i autowire into my singleton and then access the autowired bean's proprties, or?
i mean my problem is that the proxy will actually create new objects... i.e. the component is not a singleton anymore
Spencer Gibb
@spencergibb
Jan 17 2018 16:36
Beans in spring are singletons by default
Dave Syer
@dsyer
Jan 17 2018 16:39
It's nothing to do with Zookeeper
And scoped proxies are not singletons in that sense
the proxy itself is a singleton (one per spring application context)
the target is one per refresh event
So what do you mean by "singleton" and why do you care?
Viktor Gal
@vigsterkr
Jan 17 2018 16:40
@dsyer i mean if you try the one AppRefreshes
then you'll see that actually as many time as i do a curl /hello
there will be as many background scheduled threads
and actually only then
Dave Syer
@dsyer
Jan 17 2018 16:41
Not really
Viktor Gal
@vigsterkr
Jan 17 2018 16:41
the values are 'refreshed'
@dsyer based on the logs that's what's happening
Dave Syer
@dsyer
Jan 17 2018 16:41
There will be one instance of the class (one target) per refresh event
Viktor Gal
@vigsterkr
Jan 17 2018 16:42
ok so but that means there will be multiple instances... right?
Dave Syer
@dsyer
Jan 17 2018 16:42
Yes. But that's how it works
That's how scoped proxies behave
Viktor Gal
@vigsterkr
Jan 17 2018 16:42
kkk i mean that's why i said from the beginning that i might have a misconception
Dave Syer
@dsyer
Jan 17 2018 16:42
Apparently
Viktor Gal
@vigsterkr
Jan 17 2018 16:42
how i could use it
Dave Syer
@dsyer
Jan 17 2018 16:42
Where are the refresh events coming from?
Viktor Gal
@vigsterkr
Jan 17 2018 16:42
zk
Dave Syer
@dsyer
Jan 17 2018 16:43
So it is updating the values of foo and bar constantly?
Why is it sending refresh events?
Maybe that's a problem?
Viktor Gal
@vigsterkr
Jan 17 2018 16:43
?
Dave Syer
@dsyer
Jan 17 2018 16:43
(Don't know much about s-c-zk)
Spencer Gibb
@spencergibb
Jan 17 2018 16:44
zookeeper has a persistent connection and can listen for changes, unlike config server
Dave Syer
@dsyer
Jan 17 2018 16:44
But it doesn't just send refresh events if there are no changes (I hope)?
It sounds from @vigsterkr that there is a stream of refresh events from somewhere. I haven't understood that bit yet.
Spencer Gibb
@spencergibb
Jan 17 2018 16:47
if (eventType == NODE_ADDED || eventType == NODE_REMOVED || eventType == NODE_UPDATED) {
    this.publisher.publishEvent(new RefreshEvent(this, event, getEventDesc(event)));
}
Dave Syer
@dsyer
Jan 17 2018 16:51
I don't see any refreshes. Just running ZK with spring cloud kafka. Is that sufficient?
Viktor Gal
@vigsterkr
Jan 17 2018 16:52
mmm i've just tried to put everything int a Config class as a component and then use that as @Autowired in AppRefreshes... but in this case the Config class' variables are not set, i.e. it's default valued.
Dave Syer
@dsyer
Jan 17 2018 16:53
You're going to have to post code
Viktor Gal
@vigsterkr
Jan 17 2018 16:54
just pushed it
simply trying to use the AppRefreshes version
Dave Syer
@dsyer
Jan 17 2018 16:55
You don't have a default value for foo or bar. What do you mean?
Viktor Gal
@vigsterkr
Jan 17 2018 16:56
i mean that config of AppRefreshes does not have the values of the zk
only thing i changed is that i moved the mapped properties of AppRefreshes to a class named Config
Dave Syer
@dsyer
Jan 17 2018 16:56
If it has any value, then you injected it from somewhere
You didn't provide a default value in the code in github
Viktor Gal
@vigsterkr
Jan 17 2018 16:57
yeah but it has values
and it had the right values from zk
when those properties were the member of AppRefreshes
Dave Syer
@dsyer
Jan 17 2018 16:57
This is what I see
@RefreshScope
@Component
public class Config {
    @Value("${foo}")
    String foo;

    @Value("${bar}")
    Boolean bar;
}
Viktor Gal
@vigsterkr
Jan 17 2018 16:57
yes
Dave Syer
@dsyer
Jan 17 2018 16:57
There's no default value
Viktor Gal
@vigsterkr
Jan 17 2018 16:58
well it has... null and false
firhg?
*right
Dave Syer
@dsyer
Jan 17 2018 16:58
So it will fail on startup because it can't bind
Viktor Gal
@vigsterkr
Jan 17 2018 16:58
i mean it's java
Dave Syer
@dsyer
Jan 17 2018 16:58
The @Value will fail to bind
Viktor Gal
@vigsterkr
Jan 17 2018 16:58
why did it work when it was in AppRefreshes
?
the very same code
Dave Syer
@dsyer
Jan 17 2018 16:59
I assume you have a value of foo and bar in your environment
Viktor Gal
@vigsterkr
Jan 17 2018 16:59
it's in zk
and those values were properly read from zk when it was part of AppRefreshes
i mean i might totally misunderstand how this should work
but i honestly dont see why this suddenly broke
Dave Syer
@dsyer
Jan 17 2018 17:00
Then it will be the same now it is in a separate bean
Nothing is broken
Viktor Gal
@vigsterkr
Jan 17 2018 17:00
it does not contain the right values
i.e. the values in zk
if i http get on the /hello it doesn't change when i change the value in zk - that use to change
but more over it doesn't contain the initial values read from zk

now i just simply move

   @Value("${foo}")
    String foo;

    @Value("${bar}")
    Boolean bar;

into AppRefreshes

the /hello returns nicely the values in the zk
of course it will not get refreshed as @RefreshScope is missing
but still... it works
mmmm ok i see... it will only work if i access those values via getters
Viktor Gal
@vigsterkr
Jan 17 2018 17:06
i.e. if i define .getFoo() .getBar() in Config... all started to work as expected
Dave Syer
@dsyer
Jan 17 2018 17:06
Yes. That's how scoped proxies work.
I should have spotted that
You have to call a method to trigger the refresh
Viktor Gal
@vigsterkr
Jan 17 2018 17:07
oookeeey
now i'm getting somewhere :)))
Abhishek Dujari
@abshkd
Jan 17 2018 17:09
i recall this /bus endpoint from spring cloud config docs. There is not much details but it seems to work with message brokers
Dave Syer
@dsyer
Jan 17 2018 17:10
That's what a "bus" is in this context (a message broker)
Abhishek Dujari
@abshkd
Jan 17 2018 17:10
oh so it isnt actually a method? but just a name
Dave Syer
@dsyer
Jan 17 2018 17:11
What do you mean?
Abhishek Dujari
@abshkd
Jan 17 2018 17:11
i assumed it was autoconfigured route like actuator when you a broker is used and some push mechanism happens
Dave Syer
@dsyer
Jan 17 2018 17:12
Yes, there are some actuator endpoints starting with "/bus"
Abhishek Dujari
@abshkd
Jan 17 2018 17:12
since right now I call the refresh endpoint on every instance when I want to reload the bootstrap config
Dave Syer
@dsyer
Jan 17 2018 17:12
E.g. "/bus/refresh"
Abhishek Dujari
@abshkd
Jan 17 2018 17:13
thank you. Is there a better way to reloading the config for N-instances?
for bootstrap config. not the ones in refreshscope. i have not used them yet
Dave Syer
@dsyer
Jan 17 2018 17:14
Not sure what you mean
Abhishek Dujari
@abshkd
Jan 17 2018 17:14
when we change the application.yml in git we have to update the application instances with the new config
/refresh
but it needs to be done for each instance of the application like 10.0.0.1/refresh 10.0.0.2/refresh
Dave Syer
@dsyer
Jan 17 2018 17:15
Yes, but that's why we have the bus.
You send a message to the bus and it broadcasts the change
Your config server can do it for you.
Or you can use the /bus/* endpoints as a convenience
Abhishek Dujari
@abshkd
Jan 17 2018 17:16
:clap:
incredible
thank you. i will look into this and see what it takes to implement on the existing setup
what is this project called?
Spencer Gibb
@spencergibb
Jan 17 2018 17:18
spring-cloud-bus
Abhishek Dujari
@abshkd
Jan 17 2018 17:18
thank you
Abhishek Dujari
@abshkd
Jan 17 2018 17:22
thank you thank you