spring-cloud-consul icon indicating copy to clipboard operation
spring-cloud-consul copied to clipboard

RefreshEventData is package private

Open fackee opened this issue 7 years ago • 6 comments

Question

The ConfigWatch send massage to user application with spring-event-bus ,but user application can't get the event‘s data.

the configwatch:

    if (response.getValue() != null && !response.getValue().isEmpty()) {
        Long newIndex = response.getConsulIndex();

        if (newIndex != null && !newIndex.equals(currentIndex)) {
            // don't publish the same index again, don't publish the first time (-1) so index can be primed
            if (!this.consulIndexes.containsValue(newIndex) && !currentIndex.equals(-1L)) {
                RefreshEventData data = new RefreshEventData(context, currentIndex, newIndex);
                this.publisher.publishEvent(new RefreshEvent(this, data, data.toString()));
            }
            this.consulIndexes.put(context, newIndex);
        }
    }

my application lisenter

    @EventListener
    public void handle(RefreshEvent event) {
        if (this.ready.get()) {
            (RefreshEventData)event.getEvent();
        }
    }

but the RefreshEventData is a inner static class ,my application can't use it. So,who can i handle this situation?

fackee avatar Jun 14 '19 02:06 fackee

Hey @spencergibb what was the reason for sending this event? In Spring Cloud Consul repo I can't find any class reading the event.

marcingrzejszczak avatar Jul 29 '19 14:07 marcingrzejszczak

It's in commons I believe

spencergibb avatar Jul 29 '19 14:07 spencergibb

So we don't want any users to operate with that event?

marcingrzejszczak avatar Jul 29 '19 19:07 marcingrzejszczak

The event is from commons, but the data class is local to s-c-consul, but it's package private.

@dntbeSris why do you want to use that class?

spencergibb avatar Jul 29 '19 19:07 spencergibb

I need listening the consul config changed event more nimble. Although,i can loop the refresh keys like this :

 @EventListener()
    public void handle(RefreshEvent event) {
        if (this.ready.get()) {
            Set<String> keys = this.refresh.refresh();
            for(String key : keys){
                if(key.startsWith(MY_CONFIG_PREFIX)){
                     //to do something
                }
            }
        }
    }

but spring will handle this expression when consul config value contians symbol like '{}',and will throw exception.

fackee avatar Jul 30 '19 03:07 fackee

I need listening the consul config changed event more nimble. Although,i can loop the refresh keys like this :

@EventListener() public void handle(RefreshEvent event) { if (this.ready.get()) { Set keys = this.refresh.refresh(); for(String key : keys){ if(key.startsWith(MY_CONFIG_PREFIX)){ //to do something } } } }

but spring will handle this expression when consul config value contians symbol like '{}',and will throw exception.

Spencer Gibb [email protected] 于2019年7月30日周二 上午3:45写道:

The event is from commons, but the data class is local to s-c-consul, but it's package private.

@dntbeSris https://github.com/dntbeSris why do you want to use that class?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spring-cloud/spring-cloud-consul/issues/567?email_source=notifications&email_token=AD3PUXWYJFXW2FAXAXEYZHLQB5CGNA5CNFSM4HYDMET2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3BZTTY#issuecomment-516135375, or mute the thread https://github.com/notifications/unsubscribe-auth/AD3PUXQIAWHMQQXZWZ5M3KTQB5CGNANCNFSM4HYDMETQ .

fackee avatar Jul 30 '19 03:07 fackee