Closed skylarkn closed 1 year ago
custom remote events
package org.example.provider.event; import org.springframework.cloud.bus.event.RemoteApplicationEvent; public class CustomerEvent extends RemoteApplicationEvent { /** * 用户名 */ private String userName; private CustomerEvent() { } public CustomerEvent(Object source, String originService, String destinationService, String username) { super(source, originService); this.userName = username; } public String getUserName() { return userName; } }
local listener
package org.example.consumer.service; import lombok.extern.slf4j.Slf4j; import org.example.provider.event.CustomerEvent; import org.springframework.cloud.bus.event.SentApplicationEvent; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; @Slf4j @Component public class MessageService { @EventListener public void sendMessage(CustomerEvent event) { // dident work } // @EventListener // public void sendMessage2(RemoteApplicationEvent event) { // log.info("通过事件 调用方法2 : {}", event.getDestinationService()); // } // // @EventListener // public void sendMessage3(UnknownRemoteApplicationEvent event) { // log.info("通过事件 调用方法3 : {}", event.getDestinationService()); // } // @EventListener public void sendMessage4(SentApplicationEvent event) { // work event.getDestinationService() was unknow } }
Remote Application Event Scan
package org.example.consumer.config; import org.example.provider.event.CustomerEvent; import org.springframework.cloud.bus.jackson.RemoteApplicationEventScan; import org.springframework.context.annotation.Configuration; @Configuration @RemoteApplicationEventScan(basePackageClasses = CustomerEvent.class) public class BusConfiguration { }
add break points in org.springframework.cloud.bus.BusConsumer.accept(RemoteApplicationEvent event), param event are instanceof UnknownRemoteApplicationEvent
org.springframework.cloud.bus.BusConsumer.accept(RemoteApplicationEvent event)
UnknownRemoteApplicationEvent
dependency version:
<spring-boot.version>2.6.9</spring-boot.version> <spring.cloud.version>2021.0.3</spring.cloud.version> <spring.cloud.alibaba.version>2021.0.1.0</spring.cloud.alibaba.version>
me too, and depgrade to 2.x.x version is ok.
custom remote events
local listener
Remote Application Event Scan
add break points in
org.springframework.cloud.bus.BusConsumer.accept(RemoteApplicationEvent event)
, param event are instanceofUnknownRemoteApplicationEvent
dependency version: