org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent Java Examples

The following examples show how to use org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent. 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: BusAutoConfigurationTests.java    From spring-cloud-bus with Apache License 2.0 6 votes vote down vote up
@Test
public void inboundNotFromSelfWithAck() throws Exception {
	this.context = SpringApplication.run(
			new Class[] { InboundMessageHandlerConfiguration.class,
					OutboundMessageHandlerConfiguration.class,
					SentMessageConfiguration.class },
			new String[] { "--spring.cloud.bus.id=bar", "--server.port=0" });
	this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
			.send(new GenericMessage<>(
					new RefreshRemoteApplicationEvent(this, "foo", null)));
	RefreshRemoteApplicationEvent refresh = this.context
			.getBean(InboundMessageHandlerConfiguration.class).refresh;
	assertThat(refresh).isNotNull();
	OutboundMessageHandlerConfiguration outbound = this.context
			.getBean(OutboundMessageHandlerConfiguration.class);
	outbound.latch.await(2000L, TimeUnit.MILLISECONDS);
	String message = (String) outbound.message.getPayload();
	assertThat(message.contains("\"ackId\":\"" + refresh.getId()))
			.as("Wrong ackId: " + message).isTrue();
}
 
Example #2
Source File: PropertyPathEndpoint.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
@RequestMapping(method = RequestMethod.POST)
public Set<String> notifyByPath(@RequestHeader HttpHeaders headers,
		@RequestBody Map<String, Object> request) {
	PropertyPathNotification notification = this.extractor.extract(headers, request);
	if (notification != null) {

		Set<String> services = new LinkedHashSet<>();

		for (String path : notification.getPaths()) {
			services.addAll(guessServiceName(path));
		}
		if (this.applicationEventPublisher != null) {
			for (String service : services) {
				log.info("Refresh for: " + service);
				this.applicationEventPublisher.publishEvent(
						new RefreshRemoteApplicationEvent(this, this.busId, service));
			}
			return services;
		}

	}
	return Collections.emptySet();
}
 
Example #3
Source File: BusAutoConfigurationTests.java    From spring-cloud-bus with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: BusAutoConfigurationTests.java    From spring-cloud-bus with Apache License 2.0 6 votes vote down vote up
@Test
public void inboundNotFromSelfWithTrace() throws Exception {
	this.context = SpringApplication.run(
			new Class[] { InboundMessageHandlerConfiguration.class,
					OutboundMessageHandlerConfiguration.class,
					SentMessageConfiguration.class },
			new String[] { "--spring.cloud.bus.trace.enabled=true",
					"--spring.cloud.bus.id=bar", "--server.port=0" });
	this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
			.send(new GenericMessage<>(
					new RefreshRemoteApplicationEvent(this, "foo", null)));
	RefreshRemoteApplicationEvent refresh = this.context
			.getBean(InboundMessageHandlerConfiguration.class).refresh;
	assertThat(refresh).isNotNull();
	SentMessageConfiguration sent = this.context
			.getBean(SentMessageConfiguration.class);
	assertThat(sent.event).isNotNull();
	assertThat(sent.count).isEqualTo(1);
}
 
Example #5
Source File: ConfigClientTest.java    From rabbitmq-mock with Apache License 2.0 6 votes vote down vote up
@Test
void trigger_refresh() throws Exception {
    assertThatConfiguredValueIs("admin");

    configServerValues.put(ConfigClient.USER_ROLE_KEY, "dev");

    assertThatConfiguredValueIs("admin");

    contextRefreshLock.reset();

    RefreshRemoteApplicationEvent event = new RefreshRemoteApplicationEvent(this, "test-id", null);
    logger.info("\n\n <<<refresh event sent through RabbitMQ>>>\n\n");
    rabbitTemplate.convertAndSend("springCloudBus", "unused", event);

    contextRefreshLock.acquire();
    assertThatConfiguredValueIs("dev");
}
 
Example #6
Source File: SerializationTests.java    From spring-cloud-bus with Apache License 2.0 5 votes vote down vote up
@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 #7
Source File: RemoteApplicationEventScanTests.java    From spring-cloud-bus with Apache License 2.0 5 votes vote down vote up
private void addStandardSpringCloudEventBusEvents(
		final List<Class<?>> expectedRegisterdClassesAsList) {
	expectedRegisterdClassesAsList.add(AckRemoteApplicationEvent.class);
	expectedRegisterdClassesAsList.add(EnvironmentChangeRemoteApplicationEvent.class);
	expectedRegisterdClassesAsList.add(RefreshRemoteApplicationEvent.class);
	expectedRegisterdClassesAsList.add(UnknownRemoteApplicationEvent.class);
}
 
Example #8
Source File: BusAutoConfigurationTests.java    From spring-cloud-bus with Apache License 2.0 5 votes vote down vote up
@Test
public void inboundNotForSelf() {
	this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class,
			"--spring.cloud.bus.id=foo", "--server.port=0");
	this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
			.send(new GenericMessage<>(
					new RefreshRemoteApplicationEvent(this, "bar", "bar")));
	assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh)
			.isNull();
}
 
Example #9
Source File: BusAutoConfigurationTests.java    From spring-cloud-bus with Apache License 2.0 5 votes vote down vote up
@Test
public void inboundFromSelf() {
	this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class,
			"--spring.cloud.bus.id=foo", "--server.port=0");
	this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
			.send(new GenericMessage<>(
					new RefreshRemoteApplicationEvent(this, "foo", null)));
	assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh)
			.isNull();
}
 
Example #10
Source File: BusAutoConfigurationTests.java    From spring-cloud-bus with Apache License 2.0 5 votes vote down vote up
@Test
public void inboundNotFromSelf() {
	this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class,
			"--spring.cloud.bus.id=bar", "--server.port=0");
	this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
			.send(new GenericMessage<>(
					new RefreshRemoteApplicationEvent(this, "foo", null)));
	assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh)
			.isNotNull();
}
 
Example #11
Source File: SerializationTests.java    From spring-cloud-bus with Apache License 2.0 5 votes vote down vote up
@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: BusAutoConfigurationTests.java    From spring-cloud-bus with Apache License 2.0 5 votes vote down vote up
@Test
public void outboundFromSelf() throws Exception {
	this.context = SpringApplication.run(OutboundMessageHandlerConfiguration.class,
			"--debug=true", "--spring.cloud.bus.id=foo", "--server.port=0");
	this.context.publishEvent(new RefreshRemoteApplicationEvent(this, "foo", null));
	OutboundMessageHandlerConfiguration outbound = this.context
			.getBean(OutboundMessageHandlerConfiguration.class);
	outbound.latch.await(2000L, TimeUnit.MILLISECONDS);
	assertThat(outbound.message).as("message was null").isNotNull();
}
 
Example #13
Source File: BusAutoConfigurationTests.java    From spring-cloud-bus with Apache License 2.0 5 votes vote down vote up
@Test
public void outboundNotFromSelf() {
	this.context = SpringApplication.run(OutboundMessageHandlerConfiguration.class,
			"--spring.cloud.bus.id=bar", "--server.port=0");
	this.context.publishEvent(new RefreshRemoteApplicationEvent(this, "foo", null));
	assertThat(
			this.context.getBean(OutboundMessageHandlerConfiguration.class).message)
					.isNull();
}
 
Example #14
Source File: BusAutoConfigurationTests.java    From spring-cloud-bus with Apache License 2.0 5 votes vote down vote up
@Test
public void inboundNotFromSelfPathPattern() {
	this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class,
			"--spring.cloud.bus.id=bar:1000", "--server.port=0");
	this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
			.send(new GenericMessage<>(
					new RefreshRemoteApplicationEvent(this, "foo", "bar:*")));
	assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh)
			.isNotNull();
}
 
Example #15
Source File: BusAutoConfigurationTests.java    From spring-cloud-bus with Apache License 2.0 5 votes vote down vote up
@Test
public void inboundNotFromSelfDeepPathPattern() {
	this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class,
			"--spring.cloud.bus.id=bar:test:1000", "--server.port=0");
	this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
			.send(new GenericMessage<>(
					new RefreshRemoteApplicationEvent(this, "foo", "bar:**")));
	assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh)
			.isNotNull();
}
 
Example #16
Source File: BusAutoConfigurationTests.java    From spring-cloud-bus with Apache License 2.0 5 votes vote down vote up
@Test
public void inboundNotFromSelfFlatPattern() {
	this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class,
			"--spring.cloud.bus.id=bar", "--server.port=0");
	this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
			.send(new GenericMessage<>(
					new RefreshRemoteApplicationEvent(this, "foo", "bar*")));
	assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh)
			.isNotNull();
}
 
Example #17
Source File: StreamBusApplicationTests.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void business() throws Exception {
	Message<RefreshRemoteApplicationEvent> message = MessageBuilder
			.withPayload(new RefreshRemoteApplicationEvent(this, "me", "you")).build();
	this.bus.springCloudBusOutput().send(message);
	String payload = (String) this.collector.forChannel(this.bus.springCloudBusOutput()).take().getPayload();
	assertTrue("Wrong payload: " + payload, payload.contains("\"type\""));
}
 
Example #18
Source File: RefreshBusEndpoint.java    From spring-cloud-bus with Apache License 2.0 4 votes vote down vote up
@WriteOperation
public void busRefresh() {
	publish(new RefreshRemoteApplicationEvent(this, getInstanceId(), null));
}
 
Example #19
Source File: RefreshBusEndpoint.java    From spring-cloud-bus with Apache License 2.0 4 votes vote down vote up
@WriteOperation
public void busRefreshWithDestination(@Selector String destination) {
	publish(new RefreshRemoteApplicationEvent(this, getInstanceId(), destination));
}
 
Example #20
Source File: BusAutoConfigurationTests.java    From spring-cloud-bus with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(RefreshRemoteApplicationEvent event) {
	this.refresh = event;
}