use of org.springframework.messaging.simp.broker.SubscriptionRegistry in project spring-integration by spring-projects.
the class StompInboundChannelAdapterWebSocketIntegrationTests method waitForSubscribe.
private void waitForSubscribe(String destination) throws InterruptedException {
SimpleBrokerMessageHandler serverBrokerMessageHandler = this.serverContext.getBean("simpleBrokerMessageHandler", SimpleBrokerMessageHandler.class);
SubscriptionRegistry subscriptionRegistry = serverBrokerMessageHandler.getSubscriptionRegistry();
int n = 0;
while (!containsDestination(destination, subscriptionRegistry) && n++ < 100) {
Thread.sleep(100);
}
assertTrue("The subscription for the '" + destination + "' destination hasn't been registered", n < 100);
}
use of org.springframework.messaging.simp.broker.SubscriptionRegistry in project spring-integration by spring-projects.
the class StompInboundChannelAdapterWebSocketIntegrationTests method waitForUnsubscribe.
private void waitForUnsubscribe(String destination) throws InterruptedException {
SimpleBrokerMessageHandler serverBrokerMessageHandler = this.serverContext.getBean("simpleBrokerMessageHandler", SimpleBrokerMessageHandler.class);
SubscriptionRegistry subscriptionRegistry = serverBrokerMessageHandler.getSubscriptionRegistry();
int n = 0;
while (containsDestination(destination, subscriptionRegistry) && n++ < 100) {
Thread.sleep(100);
}
assertTrue("The subscription for the '" + destination + "' destination hasn't been registered", n < 100);
}
use of org.springframework.messaging.simp.broker.SubscriptionRegistry in project spring-integration by spring-projects.
the class StompIntegrationTests method waitForSubscribe.
private void waitForSubscribe(String destination) throws InterruptedException {
SimpleBrokerMessageHandler serverBrokerMessageHandler = this.serverContext.getBean("simpleBrokerMessageHandler", SimpleBrokerMessageHandler.class);
SubscriptionRegistry subscriptionRegistry = serverBrokerMessageHandler.getSubscriptionRegistry();
int n = 0;
while (!containsDestination(destination, subscriptionRegistry) && n++ < 100) {
Thread.sleep(100);
}
assertTrue("The subscription for the '" + destination + "' destination hasn't been registered", n < 100);
}
use of org.springframework.messaging.simp.broker.SubscriptionRegistry in project spring-integration by spring-projects.
the class WebSocketServerTests method testWebSocketOutboundMessageHandler.
@Test
public void testWebSocketOutboundMessageHandler() throws Exception {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
headers.setSubscriptionId("subs1");
headers.setDestination("/queue/foo");
Message<byte[]> message = MessageBuilder.withPayload(ByteBuffer.allocate(0).array()).setHeaders(headers).build();
headers = StompHeaderAccessor.create(StompCommand.SEND);
headers.setSubscriptionId("subs1");
Message<String> message2 = MessageBuilder.withPayload("Spring").setHeaders(headers).build();
this.webSocketOutputChannel.send(message);
this.webSocketOutputChannel.send(message2);
Message<?> received = this.webSocketInputChannel.receive(10000);
assertNotNull(received);
StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(received);
assertEquals(StompCommand.MESSAGE.getMessageType(), stompHeaderAccessor.getMessageType());
Object receivedPayload = received.getPayload();
assertThat(receivedPayload, instanceOf(String.class));
assertEquals("Hello Spring", receivedPayload);
SubscriptionRegistry subscriptionRegistry = this.brokerHandler.getSubscriptionRegistry();
headers = StompHeaderAccessor.create(StompCommand.MESSAGE);
headers.setDestination("/queue/foo");
message = MessageBuilder.withPayload(ByteBuffer.allocate(0).array()).setHeaders(headers).build();
MultiValueMap<String, String> subscriptions = subscriptionRegistry.findSubscriptions(message);
assertFalse(subscriptions.isEmpty());
List<String> subscription = subscriptions.values().iterator().next();
assertEquals(1, subscription.size());
assertEquals("subs1", subscription.get(0));
Message<?> event = this.webSocketEvents.receive(10000);
assertNotNull(event);
assertThat(event.getPayload(), instanceOf(WebSocketSession.class));
verify(this.requestUpgradeStrategy).start();
}
Aggregations