Search in sources :

Example 1 with SubscriptionRegistry

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);
}
Also used : SubscriptionRegistry(org.springframework.messaging.simp.broker.SubscriptionRegistry) SimpleBrokerMessageHandler(org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler)

Example 2 with SubscriptionRegistry

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);
}
Also used : SubscriptionRegistry(org.springframework.messaging.simp.broker.SubscriptionRegistry) SimpleBrokerMessageHandler(org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler)

Example 3 with SubscriptionRegistry

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);
}
Also used : SubscriptionRegistry(org.springframework.messaging.simp.broker.SubscriptionRegistry) SimpleBrokerMessageHandler(org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler)

Example 4 with SubscriptionRegistry

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();
}
Also used : SubscriptionRegistry(org.springframework.messaging.simp.broker.SubscriptionRegistry) StompHeaderAccessor(org.springframework.messaging.simp.stomp.StompHeaderAccessor) Matchers.containsString(org.hamcrest.Matchers.containsString) WebSocketSession(org.springframework.web.socket.WebSocketSession) Test(org.junit.Test)

Aggregations

SubscriptionRegistry (org.springframework.messaging.simp.broker.SubscriptionRegistry)4 SimpleBrokerMessageHandler (org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler)3 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1 StompHeaderAccessor (org.springframework.messaging.simp.stomp.StompHeaderAccessor)1 WebSocketSession (org.springframework.web.socket.WebSocketSession)1