org.springframework.cloud.bus.event.RemoteApplicationEvent Java Examples
The following examples show how to use
org.springframework.cloud.bus.event.RemoteApplicationEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SubtypeModuleTests.java From spring-cloud-bus with Apache License 2.0 | 6 votes |
@Test public void testDeserializeUnknownTypeWithMessageConverter() throws Exception { BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null); converter.afterPropertiesSet(); Object event = converter.fromMessage(MessageBuilder .withPayload("{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}") .build(), RemoteApplicationEvent.class); assertThat(event instanceof UnknownRemoteApplicationEvent) .as("event is wrong type").isTrue(); assertThat(((UnknownRemoteApplicationEvent) event).getTypeInfo()) .as("type information is wrong") .isEqualTo("NotDefinedTestRemoteApplicationEvent"); assertThat(((UnknownRemoteApplicationEvent) event).getPayloadAsString()) .as("payload is wrong") .isEqualTo("{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}"); }
Example #2
Source File: EventVerifier.java From hawkbit with Eclipse Public License 1.0 | 6 votes |
@Override public void onApplicationEvent(final RemoteApplicationEvent event) { LOGGER.debug("Received event {}", event.getClass().getSimpleName()); if (ResetCounterMarkerEvent.class.isAssignableFrom(event.getClass())) { LOGGER.debug("Retrieving reset counter marker event - resetting counters"); capturedEvents.clear(); return; } if (event instanceof RemoteTenantAwareEvent) { assertThat(((RemoteTenantAwareEvent) event).getTenant()).isNotEmpty(); } if (event instanceof RemoteIdEvent) { assertThat(((RemoteIdEvent) event).getEntityId()).isNotNull(); } if (event instanceof TargetAssignDistributionSetEvent) { assertThat(((TargetAssignDistributionSetEvent) event).getActions()).isNotEmpty(); assertThat(((TargetAssignDistributionSetEvent) event).getDistributionSetId()).isNotNull(); } capturedEvents.add(event.getClass()); }
Example #3
Source File: BusJacksonAutoConfiguration.java From spring-cloud-bus with Apache License 2.0 | 6 votes |
private Class<?>[] findSubTypes() { List<Class<?>> types = new ArrayList<>(); if (this.packagesToScan != null) { for (String pkg : this.packagesToScan) { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider( false); provider.addIncludeFilter( new AssignableTypeFilter(RemoteApplicationEvent.class)); Set<BeanDefinition> components = provider.findCandidateComponents(pkg); for (BeanDefinition component : components) { try { types.add(Class.forName(component.getBeanClassName())); } catch (ClassNotFoundException e) { throw new IllegalStateException( "Failed to scan classpath for remote event classes", e); } } } } if (log.isDebugEnabled()) { log.debug("Found sub types: " + types); } return types.toArray(new Class<?>[0]); }
Example #4
Source File: SubtypeModuleTests.java From spring-cloud-bus with Apache License 2.0 | 6 votes |
@Test public void testDeserializeSubclass() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new SubtypeModule(MyRemoteApplicationEvent.class)); RemoteApplicationEvent event = mapper.readValue( "{\"type\":\"my\", \"destinationService\":\"myservice\", \"originService\":\"myorigin\"}", RemoteApplicationEvent.class); assertThat(event instanceof MyRemoteApplicationEvent).as("event is wrong type") .isTrue(); MyRemoteApplicationEvent myEvent = MyRemoteApplicationEvent.class.cast(event); assertThat(myEvent.getOriginService()).as("originService was wrong") .isEqualTo("myorigin"); assertThat(myEvent.getDestinationService()).as("destinationService was wrong") .isEqualTo("myservice"); }
Example #5
Source File: ServiceMatcher.java From spring-cloud-bus with Apache License 2.0 | 6 votes |
public boolean isForSelf(RemoteApplicationEvent event) { String destinationService = event.getDestinationService(); if (destinationService == null || destinationService.trim().isEmpty() || this.matcher.match(destinationService, getServiceId())) { return true; } // Check all potential config names instead of service name for (String configName : this.configNames) { if (this.matcher.match(destinationService, configName)) { return true; } } return false; }
Example #6
Source File: BusAutoConfiguration.java From spring-cloud-bus with Apache License 2.0 | 5 votes |
@StreamListener(SpringCloudBusClient.INPUT) public void acceptRemote(RemoteApplicationEvent event) { if (event instanceof AckRemoteApplicationEvent) { if (this.bus.getTrace().isEnabled() && !this.serviceMatcher.isFromSelf(event) && this.applicationEventPublisher != null) { this.applicationEventPublisher.publishEvent(event); } // If it's an ACK we are finished processing at this point return; } if (log.isDebugEnabled()) { log.debug("Received remote event from bus: " + event); } if (this.serviceMatcher.isForSelf(event) && this.applicationEventPublisher != null) { if (!this.serviceMatcher.isFromSelf(event)) { this.applicationEventPublisher.publishEvent(event); } if (this.bus.getAck().isEnabled()) { AckRemoteApplicationEvent ack = new AckRemoteApplicationEvent(this, this.serviceMatcher.getServiceId(), this.bus.getAck().getDestinationService(), event.getDestinationService(), event.getId(), event.getClass()); this.cloudBusOutboundChannel .send(MessageBuilder.withPayload(ack).build()); this.applicationEventPublisher.publishEvent(ack); } } if (this.bus.getTrace().isEnabled() && this.applicationEventPublisher != null) { // We are set to register sent events so publish it for local consumption, // irrespective of the origin this.applicationEventPublisher.publishEvent(new SentApplicationEvent(this, event.getOriginService(), event.getDestinationService(), event.getId(), event.getClass())); } }
Example #7
Source File: SubtypeModuleTests.java From spring-cloud-bus with Apache License 2.0 | 5 votes |
@Test public void testDeserializeWithMessageConverter() throws Exception { BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null); converter.afterPropertiesSet(); Object event = converter.fromMessage(MessageBuilder .withPayload("{\"type\":\"TestRemoteApplicationEvent\"}").build(), RemoteApplicationEvent.class); assertThat(event instanceof TestRemoteApplicationEvent).as("event is wrong type") .isTrue(); }
Example #8
Source File: SubtypeModuleTests.java From spring-cloud-bus with Apache License 2.0 | 5 votes |
@Test public void testDeserializeCustomizedObjectMapper() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); BusJacksonMessageConverter converter = new BusJacksonMessageConverter(mapper); converter.afterPropertiesSet(); Object event = converter.fromMessage(MessageBuilder.withPayload( "{\"type\":\"TestRemoteApplicationEvent\", \"origin_service\":\"myorigin\"}") .build(), RemoteApplicationEvent.class); assertThat(event).isNotNull().isInstanceOf(TestRemoteApplicationEvent.class); assertThat(TestRemoteApplicationEvent.class.cast(event).getOriginService()) .isEqualTo("myorigin"); }
Example #9
Source File: SubtypeModuleTests.java From spring-cloud-bus with Apache License 2.0 | 5 votes |
@Test public void testDeserializeWhenTypeIsKnown() throws Exception { ObjectMapper mapper = new ObjectMapper(); RemoteApplicationEvent event = mapper.readValue("{\"type\":\"another\"}", AnotherRemoteApplicationEvent.class); assertThat(event instanceof AnotherRemoteApplicationEvent) .as("event is wrong type").isTrue(); }
Example #10
Source File: SerializationTests.java From spring-cloud-bus with Apache License 2.0 | 5 votes |
@Test public void deserializeOldValueWithNoId() throws Exception { this.mapper.registerModule(new SubtypeModule(RefreshRemoteApplicationEvent.class, EnvironmentChangeRemoteApplicationEvent.class)); EnvironmentChangeRemoteApplicationEvent source = new EnvironmentChangeRemoteApplicationEvent( this, "foo", "bar", Collections.<String, String>emptyMap()); String value = this.mapper.writeValueAsString(source); value = value.replaceAll(",\"id\":\"[a-f0-9-]*\"", ""); RemoteApplicationEvent event = this.mapper.readValue(value, RemoteApplicationEvent.class); assertThat(event instanceof EnvironmentChangeRemoteApplicationEvent).isTrue(); assertThat(event.getId()).isNotNull(); assertThat(event.getId().equals(source.getId())).isFalse(); }
Example #11
Source File: SerializationTests.java From spring-cloud-bus with Apache License 2.0 | 5 votes |
@Test public void vanillaDeserialize() throws Exception { this.mapper.registerModule(new SubtypeModule(RefreshRemoteApplicationEvent.class, EnvironmentChangeRemoteApplicationEvent.class)); EnvironmentChangeRemoteApplicationEvent source = new EnvironmentChangeRemoteApplicationEvent( this, "foo", "bar", Collections.<String, String>emptyMap()); String value = this.mapper.writeValueAsString(source); RemoteApplicationEvent event = this.mapper.readValue(value, RemoteApplicationEvent.class); assertThat(event instanceof EnvironmentChangeRemoteApplicationEvent).isTrue(); assertThat(event.getId()).isNotNull(); assertThat(event.getId().equals(source.getId())).isTrue(); }
Example #12
Source File: SubtypeModuleTests.java From spring-cloud-bus with Apache License 2.0 | 5 votes |
@Test public void testDeserializeJsonTypeWithMessageConverter() throws Exception { BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null); converter.afterPropertiesSet(); Object event = converter.fromMessage( MessageBuilder.withPayload("{\"type\":\"typed\"}").build(), RemoteApplicationEvent.class); assertThat(event instanceof TypedRemoteApplicationEvent).as("event is wrong type") .isTrue(); }
Example #13
Source File: BusAutoConfiguration.java From spring-cloud-bus with Apache License 2.0 | 5 votes |
@EventListener(classes = RemoteApplicationEvent.class) public void acceptLocal(RemoteApplicationEvent event) { if (this.serviceMatcher.isFromSelf(event) && !(event instanceof AckRemoteApplicationEvent)) { if (log.isDebugEnabled()) { log.debug("Sending remote event on bus: " + event); } this.cloudBusOutboundChannel.send(MessageBuilder.withPayload(event).build()); } }
Example #14
Source File: SubtypeModuleTests.java From spring-cloud-bus with Apache License 2.0 | 5 votes |
/** * see https://github.com/spring-cloud/spring-cloud-bus/issues/74 */ @Test public void testDeserializeAckRemoteApplicationEventWithKnownType() throws Exception { BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null); converter.afterPropertiesSet(); Object event = converter.fromMessage(MessageBuilder .withPayload("{\"type\":\"AckRemoteApplicationEvent\", " + "\"event\":\"org.springframework.cloud.bus.event.test.TestRemoteApplicationEvent\"}") .build(), RemoteApplicationEvent.class); assertThat(event instanceof AckRemoteApplicationEvent).as("event is no ack") .isTrue(); AckRemoteApplicationEvent ackEvent = AckRemoteApplicationEvent.class.cast(event); assertThat(ackEvent.getEvent()).as("inner ack event has wrong type") .isEqualTo(TestRemoteApplicationEvent.class); }
Example #15
Source File: SubtypeModuleTests.java From spring-cloud-bus with Apache License 2.0 | 5 votes |
/** * see https://github.com/spring-cloud/spring-cloud-bus/issues/74 */ @Test public void testDeserializeAckRemoteApplicationEventWithUnknownType() throws Exception { BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null); converter.afterPropertiesSet(); Object event = converter.fromMessage(MessageBuilder.withPayload( "{\"type\":\"AckRemoteApplicationEvent\", \"event\":\"foo.bar.TestRemoteApplicationEvent\"}") .build(), RemoteApplicationEvent.class); assertThat(event instanceof AckRemoteApplicationEvent).as("event is no ack") .isTrue(); AckRemoteApplicationEvent ackEvent = AckRemoteApplicationEvent.class.cast(event); assertThat(ackEvent.getEvent()).as("inner ack event has wrong type") .isEqualTo(UnknownRemoteApplicationEvent.class); }
Example #16
Source File: BusProtoStuffMessageConverterTest.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
@Test @Description("Verifies that the TargetCreatedEvent can be successfully serialized and deserialized") public void successfullySerializeAndDeserializeEvent() { final TargetCreatedEvent targetCreatedEvent = new TargetCreatedEvent(targetMock, "1"); // serialize final Object serializedEvent = underTest.convertToInternal(targetCreatedEvent, new MessageHeaders(new HashMap<>()), null); assertThat(serializedEvent).isInstanceOf(byte[].class); // deserialize when(messageMock.getPayload()).thenReturn(serializedEvent); final Object deserializedEvent = underTest.convertFromInternal(messageMock, RemoteApplicationEvent.class, null); assertThat(deserializedEvent).isInstanceOf(TargetCreatedEvent.class); assertThat(deserializedEvent).isEqualTo(targetCreatedEvent); }
Example #17
Source File: AbstractRemoteEventTest.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
@Before public void setup() throws Exception { final BusJacksonAutoConfiguration autoConfiguration = new BusJacksonAutoConfiguration(); this.jacksonMessageConverter = autoConfiguration.busJsonConverter(null); ReflectionTestUtils.setField(jacksonMessageConverter, "packagesToScan", new String[] { "org.eclipse.hawkbit.repository.event.remote", ClassUtils.getPackageName(RemoteApplicationEvent.class) }); ((InitializingBean) jacksonMessageConverter).afterPropertiesSet(); }
Example #18
Source File: Log4j2EventListener.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@StreamListener(SpringCloudBusClient.INPUT) public void acceptRemote(RemoteApplicationEvent event) { LOGGER.debug("Refresh application event triggered"); WatchEventManager.publishEvent(); }
Example #19
Source File: Log4j2EventListener.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@EventListener(classes = RemoteApplicationEvent.class) public void acceptLocal(RemoteApplicationEvent event) { LOGGER.debug("Refresh application event triggered"); WatchEventManager.publishEvent(); }
Example #20
Source File: ServiceMatcher.java From spring-cloud-bus with Apache License 2.0 | 4 votes |
public boolean isFromSelf(RemoteApplicationEvent event) { String originService = event.getOriginService(); String serviceId = getServiceId(); return this.matcher.match(originService, serviceId); }
Example #21
Source File: BusJacksonAutoConfiguration.java From spring-cloud-bus with Apache License 2.0 | 4 votes |
@Override protected boolean supports(Class<?> aClass) { // This converter applies only to RemoteApplicationEvent and subclasses return RemoteApplicationEvent.class.isAssignableFrom(aClass); }
Example #22
Source File: AmqpMessageDispatcherService.java From hawkbit with Eclipse Public License 1.0 | 4 votes |
private boolean isFromSelf(final RemoteApplicationEvent event) { return serviceMatcher == null || serviceMatcher.isFromSelf(event); }
Example #23
Source File: AmqpMessageDispatcherService.java From hawkbit with Eclipse Public License 1.0 | 4 votes |
protected boolean shouldBeProcessed(final RemoteApplicationEvent event) { return isFromSelf(event); }
Example #24
Source File: BusProtoStuffMessageConverter.java From hawkbit with Eclipse Public License 1.0 | 4 votes |
@Override protected boolean supports(final Class<?> aClass) { return RemoteApplicationEvent.class.isAssignableFrom(aClass); }