spring-cloud / spring-cloud-bus

Spring Cloud event bus
http://cloud.spring.io/spring-cloud-bus/
Apache License 2.0
409 stars 242 forks source link

Event broadcasting with SpringBoot 2 and Finchley not work #133

Closed paulux84 closed 5 years ago

paulux84 commented 6 years ago

Hello, I've downloaded the following project https://github.com/tndavidson/spring-cloud-bus-custom-events and everything seems to work, but when I upgrade dependency trail to Spring Boot 2 and Finchley, the event MyCustomRemoteEvent is delivered only to the instance that has raised it. You can find in the following url the git project with the same very problem https://github.com/paulux84/spring-cloud-bus-custom-events

Thanks

ExtremeYu commented 6 years ago

YES,i find the same issue ,the on of the reason is the ServiceMatcher line 35 ,it always to false so that the BusAutoConfiguration line 121 this.cloudBusOutboundChannel.send(MessageBuilder.withPayload(event).build()); will never work

messaoudi-mounir commented 6 years ago

The service matcher try to match originService (in the spring-cloud-bus-custom-events is equal to context.getId() ) with ServiceMatcher .getServiceId() who correspond to spring.application.instance_id (if you are using eureka it's eureka.instance.instance-id)

String originService = event.getOriginService(); String serviceId = this.getServiceId();

To bypass the issue, you can inject ServiceMatcher and replace final String myUniqueId = context.getId(); // each service instance must have a unique context ID by final String myUniqueId = serviceMatcher.getServiceId();

or get value from config (not tested) @Value("${spring.application.instance_id}") private String myUniqueId ;

nb. spring.application.index is deprecated in springboot 2 and by default is unique.

spencergibb commented 6 years ago

You need to provide a spring.application.name.

messaoudi-mounir commented 6 years ago

Even if you provide pring.application.name, I run 2 instances of app over eureka + cloud config server:

spencergibb commented 6 years ago

Monitor has issues with app names that have dashes in them

spencergibb commented 5 years ago

Actually, I've seen this work with app names that have dashes. can you update to Finchley.SR2 and try again?

spring-projects-issues commented 5 years ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

paulux84 commented 5 years ago

Hi, i've updated dependendency to Finchley.SR2 but not work. I've also tried with Greenwich and Spring Boot 2.1.3 but not work. I've also tried with kafka binder but not work. I've updated the test project so you can reproduce the problem https://github.com/paulux84/spring-cloud-bus-custom-events

ugurlu commented 5 years ago

When creating an event try using.

@Autowired
BusProperties busProperties;

...
...

new MyCustomEvent(this, busProperties.getId(), null);
paulux84 commented 5 years ago

When creating an event try using.

@Autowired
BusProperties busProperties;

...
...

new MyCustomEvent(this, busProperties.getId(), null);

This trick do the work. Thanks