Search in sources :

Example 6 with SimpleBrokerMessageHandler

use of org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler 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 7 with SimpleBrokerMessageHandler

use of org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler 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 8 with SimpleBrokerMessageHandler

use of org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler 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 9 with SimpleBrokerMessageHandler

use of org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler in project spring-framework by spring-projects.

the class MessageBrokerConfigurationTests method customCacheLimit.

@Test
public void customCacheLimit() {
    ApplicationContext context = loadConfig(CustomConfig.class);
    SimpleBrokerMessageHandler broker = context.getBean(SimpleBrokerMessageHandler.class);
    DefaultSubscriptionRegistry registry = (DefaultSubscriptionRegistry) broker.getSubscriptionRegistry();
    assertThat(registry.getCacheLimit()).isEqualTo(8192);
}
Also used : DefaultSubscriptionRegistry(org.springframework.messaging.simp.broker.DefaultSubscriptionRegistry) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) SimpleBrokerMessageHandler(org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler) Test(org.junit.jupiter.api.Test)

Example 10 with SimpleBrokerMessageHandler

use of org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler in project spring-framework by spring-projects.

the class MessageBrokerConfigurationTests method clientOutboundChannelUsedBySimpleBroker.

@Test
public void clientOutboundChannelUsedBySimpleBroker() {
    ApplicationContext context = loadConfig(SimpleBrokerConfig.class);
    TestChannel outboundChannel = context.getBean("clientOutboundChannel", TestChannel.class);
    SimpleBrokerMessageHandler broker = context.getBean(SimpleBrokerMessageHandler.class);
    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
    headers.setSessionId("sess1");
    headers.setSubscriptionId("subs1");
    headers.setDestination("/foo");
    Message<?> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());
    // subscribe
    broker.handleMessage(createConnectMessage("sess1", new long[] { 0, 0 }));
    broker.handleMessage(message);
    headers = StompHeaderAccessor.create(StompCommand.SEND);
    headers.setSessionId("sess1");
    headers.setDestination("/foo");
    message = MessageBuilder.createMessage("bar".getBytes(), headers.getMessageHeaders());
    // message
    broker.handleMessage(message);
    message = outboundChannel.messages.get(1);
    headers = StompHeaderAccessor.wrap(message);
    assertThat(headers.getMessageType()).isEqualTo(SimpMessageType.MESSAGE);
    assertThat(headers.getDestination()).isEqualTo("/foo");
    assertThat(new String((byte[]) message.getPayload())).isEqualTo("bar");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) SimpleBrokerMessageHandler(org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler) StompHeaderAccessor(org.springframework.messaging.simp.stomp.StompHeaderAccessor) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleBrokerMessageHandler (org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler)13 Test (org.junit.jupiter.api.Test)6 ApplicationContext (org.springframework.context.ApplicationContext)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)4 DefaultSubscriptionRegistry (org.springframework.messaging.simp.broker.DefaultSubscriptionRegistry)3 SubscriptionRegistry (org.springframework.messaging.simp.broker.SubscriptionRegistry)3 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)2 Nullable (org.springframework.lang.Nullable)2 SimpAnnotationMethodMessageHandler (org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler)2 StompBrokerRelayMessageHandler (org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler)2 DefaultUserDestinationResolver (org.springframework.messaging.simp.user.DefaultUserDestinationResolver)2 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)2 ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)2 ArrayList (java.util.ArrayList)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 Bean (org.springframework.context.annotation.Bean)1 MessageHandler (org.springframework.messaging.MessageHandler)1 ByteArrayMessageConverter (org.springframework.messaging.converter.ByteArrayMessageConverter)1