Java源码示例:org.springframework.cloud.bus.event.AckRemoteApplicationEvent

示例1
@Test
public void inboundAckWithTrace() throws Exception {
	this.context = SpringApplication.run(
			new Class[] { InboundMessageHandlerConfiguration.class,
					OutboundMessageHandlerConfiguration.class,
					AckMessageConfiguration.class },
			new String[] { "--spring.cloud.bus.trace.enabled=true",
					"--spring.cloud.bus.id=bar", "--server.port=0" });
	this.context.getBean(BusProperties.class).setId("bar");
	this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
			.send(new GenericMessage<>(new AckRemoteApplicationEvent(this, "foo",
					null, "ID", "bar", RefreshRemoteApplicationEvent.class)));
	AckMessageConfiguration sent = this.context
			.getBean(AckMessageConfiguration.class);
	assertThat(sent.event).isNotNull();
	assertThat(sent.count).isEqualTo(1);
}
 
示例2
@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());
	}
}
 
示例3
@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()));
	}
}
 
示例4
/**
 * 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);
}
 
示例5
/**
 * 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);
}
 
示例6
private void addStandardSpringCloudEventBusEvents(
		final List<Class<?>> expectedRegisterdClassesAsList) {
	expectedRegisterdClassesAsList.add(AckRemoteApplicationEvent.class);
	expectedRegisterdClassesAsList.add(EnvironmentChangeRemoteApplicationEvent.class);
	expectedRegisterdClassesAsList.add(RefreshRemoteApplicationEvent.class);
	expectedRegisterdClassesAsList.add(UnknownRemoteApplicationEvent.class);
}
 
示例7
@EventListener
public void onAckEvent(AckRemoteApplicationEvent event)
    throws JsonProcessingException {
    System.out.printf("ServiceId [%s] listeners on %s\n", serviceId,
        objectMapper.writeValueAsString(event));
}
 
示例8
@EventListener
public void onAckEvent(AckRemoteApplicationEvent event)
    throws JsonProcessingException {
    System.out.printf("ServiceId [%s] listeners on %s\n", serviceId,
        objectMapper.writeValueAsString(event));
}
 
示例9
@EventListener
public void onAckEvent(AckRemoteApplicationEvent event)
    throws JsonProcessingException {
    System.out.printf("ServiceId [%s] listeners on %s\n", serviceId,
        objectMapper.writeValueAsString(event));
}
 
示例10
@EventListener
public void onAckEvent(AckRemoteApplicationEvent event)
    throws JsonProcessingException {
    System.out.printf("ServiceId [%s] listeners on %s\n", serviceId,
        objectMapper.writeValueAsString(event));
}
 
示例11
@EventListener
public void onAckEvent(AckRemoteApplicationEvent event)
    throws JsonProcessingException {
    System.out.printf("ServiceId [%s] listeners on %s\n", serviceId,
        objectMapper.writeValueAsString(event));
}
 
示例12
@EventListener
public void onAckEvent(AckRemoteApplicationEvent event)
		throws JsonProcessingException {
	System.out.printf("Server [port : %d] listeners on %s\n", localServerPort,
			objectMapper.writeValueAsString(event));
}
 
示例13
@Override
public void onApplicationEvent(AckRemoteApplicationEvent event) {
	this.event = event;
	this.count++;
}