org.springframework.messaging.support.ExecutorSubscribableChannel Java Examples
The following examples show how to use
org.springframework.messaging.support.ExecutorSubscribableChannel.
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: StompSubProtocolHandlerTests.java From java-technology-stack with MIT License | 6 votes |
@Test // SPR-14690 public void handleMessageFromClientWithTokenAuthentication() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(); channel.addInterceptor(new AuthenticationInterceptor("[email protected]")); channel.addInterceptor(new ImmutableMessageChannelInterceptor()); TestMessageHandler messageHandler = new TestMessageHandler(); channel.subscribe(messageHandler); StompSubProtocolHandler handler = new StompSubProtocolHandler(); handler.afterSessionStarted(this.session, channel); TextMessage wsMessage = StompTextMessageBuilder.create(StompCommand.CONNECT).build(); handler.handleMessageFromClient(this.session, wsMessage, channel); assertEquals(1, messageHandler.getMessages().size()); Message<?> message = messageHandler.getMessages().get(0); Principal user = SimpMessageHeaderAccessor.getUser(message.getHeaders()); assertNotNull(user); assertEquals("[email protected]", user.getName()); }
Example #2
Source File: TestConsumer.java From spring-cloud-consul with Apache License 2.0 | 6 votes |
@Override public void run(ApplicationArguments args) throws Exception { logger.info("Consumer running with binder {}", this.binder); SubscribableChannel consumerChannel = new ExecutorSubscribableChannel(); consumerChannel.subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { TestConsumer.this.messagePayload = (String) message.getPayload(); logger.info("Received message: {}", TestConsumer.this.messagePayload); } }); String group = null; if (args.containsOption("group")) { group = args.getOptionValues("group").get(0); } this.binder.bindConsumer(ConsulBinderTests.BINDING_NAME, group, consumerChannel, new ConsumerProperties()); this.isBound = true; }
Example #3
Source File: StompSubProtocolHandlerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test // SPR-14690 public void handleMessageFromClientWithTokenAuthentication() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(); channel.addInterceptor(new AuthenticationInterceptor("[email protected]")); channel.addInterceptor(new ImmutableMessageChannelInterceptor()); TestMessageHandler messageHandler = new TestMessageHandler(); channel.subscribe(messageHandler); StompSubProtocolHandler handler = new StompSubProtocolHandler(); handler.afterSessionStarted(this.session, channel); TextMessage wsMessage = StompTextMessageBuilder.create(StompCommand.CONNECT).build(); handler.handleMessageFromClient(this.session, wsMessage, channel); assertEquals(1, messageHandler.getMessages().size()); Message<?> message = messageHandler.getMessages().get(0); Principal user = SimpMessageHeaderAccessor.getUser(message.getHeaders()); assertNotNull(user); assertEquals("[email protected]", user.getName()); }
Example #4
Source File: OrderedMessageSenderTests.java From spring-analysis-note with MIT License | 5 votes |
@Before public void setup() { this.executor = new ThreadPoolTaskExecutor(); this.executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2); this.executor.setAllowCoreThreadTimeOut(true); this.executor.afterPropertiesSet(); this.channel = new ExecutorSubscribableChannel(this.executor); OrderedMessageSender.configureOutboundChannel(this.channel, true); this.sender = new OrderedMessageSender(this.channel, logger); }
Example #5
Source File: AbstractMessageBrokerConfiguration.java From spring-analysis-note with MIT License | 5 votes |
@Bean public AbstractSubscribableChannel clientOutboundChannel() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientOutboundChannelExecutor()); channel.setLogger(SimpLogging.forLog(channel.getLogger())); ChannelRegistration reg = getClientOutboundChannelRegistration(); if (reg.hasInterceptors()) { channel.setInterceptors(reg.getInterceptors()); } return channel; }
Example #6
Source File: TracingChannelInterceptorTest.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
@Test public void should_store_broker_as_remote_service_name_when_no_special_headers_were_found() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(); channel.addInterceptor(this.interceptor); List<Message<?>> messages = new ArrayList<>(); channel.subscribe(messages::add); Map<String, Object> headers = new HashMap<>(); channel.send(MessageBuilder.createMessage("foo", new MessageHeaders(headers))); assertThat(this.spans).extracting(MutableSpan::remoteServiceName) .containsOnly("broker", null); }
Example #7
Source File: TracingChannelInterceptorTest.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
@Test public void should_store_rabbitmq_as_remote_service_name_when_rabbit_header_is_present() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(); channel.addInterceptor(this.interceptor); List<Message<?>> messages = new ArrayList<>(); channel.subscribe(messages::add); Map<String, Object> headers = new HashMap<>(); headers.put(AmqpHeaders.RECEIVED_ROUTING_KEY, "hello"); channel.send(MessageBuilder.createMessage("foo", new MessageHeaders(headers))); assertThat(this.spans).extracting(MutableSpan::remoteServiceName) .contains("rabbitmq"); }
Example #8
Source File: TracingChannelInterceptorTest.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
@Test public void should_store_kafka_as_remote_service_name_when_kafka_header_is_present() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(); channel.addInterceptor(this.interceptor); List<Message<?>> messages = new ArrayList<>(); channel.subscribe(messages::add); Map<String, Object> headers = new HashMap<>(); headers.put(KafkaHeaders.MESSAGE_KEY, "hello"); channel.send(MessageBuilder.createMessage("foo", new MessageHeaders(headers))); assertThat(this.spans).extracting(MutableSpan::remoteServiceName) .contains("kafka"); }
Example #9
Source File: TracingChannelInterceptorTest.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
@Test public void integrated_sendAndSubscriber() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(); channel.addInterceptor(this.interceptor); List<Message<?>> messages = new ArrayList<>(); channel.subscribe(messages::add); channel.send(MessageBuilder.withPayload("foo").build()); assertThat(this.spans).extracting(MutableSpan::kind) .containsExactly(Span.Kind.CONSUMER, null, Span.Kind.PRODUCER); }
Example #10
Source File: TracingChannelInterceptorTest.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
@Test public void subscriber_removesTraceIdsFromMessage_nativeHeaders() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(); channel.addInterceptor(this.interceptor); List<Message<?>> messages = new ArrayList<>(); channel.subscribe(messages::add); channel.send(MessageBuilder.withPayload("foo").build()); assertThat((Map) messages.get(0).getHeaders().get(NATIVE_HEADERS)) .doesNotContainKeys("b3"); }
Example #11
Source File: TracingChannelInterceptorTest.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
/** * The subscriber consumes a message then synchronously processes it. Since we only * inject trace IDs on unprocessed messages, we remove IDs to prevent accidental * re-use of the same span. */ @Test public void subscriber_removesTraceIdsFromMessage() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(); channel.addInterceptor(this.interceptor); List<Message<?>> messages = new ArrayList<>(); channel.subscribe(messages::add); channel.send(MessageBuilder.withPayload("foo").build()); assertThat(messages.get(0).getHeaders()).doesNotContainKeys("b3"); }
Example #12
Source File: TracingChannelInterceptorTest.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
@Test public void subscriber_startsAndStopsConsumerAndProcessingSpan() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(); channel.addInterceptor(executorSideOnly(this.interceptor)); List<Message<?>> messages = new ArrayList<>(); channel.subscribe(messages::add); channel.send(MessageBuilder.withPayload("foo").build()); assertThat(messages.get(0).getHeaders()).doesNotContainKeys("b3", "nativeHeaders"); assertThat(this.spans).extracting(MutableSpan::kind) .containsExactly(Span.Kind.CONSUMER, null); }
Example #13
Source File: GenericMessagingTemplateTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void sendAndReceive() { SubscribableChannel channel = new ExecutorSubscribableChannel(this.executor); channel.subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel(); replyChannel.send(new GenericMessage<String>("response")); } }); String actual = this.template.convertSendAndReceive(channel, "request", String.class); assertEquals("response", actual); }
Example #14
Source File: StompBrokerRelayMessageHandlerIntegrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { logger.debug("Setting up before '" + this.testName.getMethodName() + "'"); this.port = SocketUtils.findAvailableTcpPort(61613); this.responseChannel = new ExecutorSubscribableChannel(); this.responseHandler = new TestMessageHandler(); this.responseChannel.subscribe(this.responseHandler); this.eventPublisher = new TestEventPublisher(); startActiveMqBroker(); createAndStartRelay(); }
Example #15
Source File: AbstractMessageBrokerConfiguration.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Bean public AbstractSubscribableChannel brokerChannel() { ChannelRegistration reg = getBrokerRegistry().getBrokerChannelRegistration(); ExecutorSubscribableChannel channel = reg.hasTaskExecutor() ? new ExecutorSubscribableChannel(brokerChannelExecutor()) : new ExecutorSubscribableChannel(); reg.setInterceptors(new ImmutableMessageChannelInterceptor()); channel.setInterceptors(reg.getInterceptors()); return channel; }
Example #16
Source File: AbstractMessageBrokerConfiguration.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Bean public AbstractSubscribableChannel clientOutboundChannel() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientOutboundChannelExecutor()); ChannelRegistration reg = getClientOutboundChannelRegistration(); channel.setInterceptors(reg.getInterceptors()); return channel; }
Example #17
Source File: AbstractMessageBrokerConfiguration.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Bean public AbstractSubscribableChannel clientInboundChannel() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientInboundChannelExecutor()); ChannelRegistration reg = getClientInboundChannelRegistration(); channel.setInterceptors(reg.getInterceptors()); return channel; }
Example #18
Source File: AbstractMessageBrokerConfiguration.java From spring-analysis-note with MIT License | 5 votes |
@Bean public AbstractSubscribableChannel clientInboundChannel() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientInboundChannelExecutor()); channel.setLogger(SimpLogging.forLog(channel.getLogger())); ChannelRegistration reg = getClientInboundChannelRegistration(); if (reg.hasInterceptors()) { channel.setInterceptors(reg.getInterceptors()); } return channel; }
Example #19
Source File: GenericMessagingTemplateTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void sendAndReceive() { SubscribableChannel channel = new ExecutorSubscribableChannel(this.executor); channel.subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel(); replyChannel.send(new GenericMessage<>("response")); } }); String actual = this.template.convertSendAndReceive(channel, "request", String.class); assertEquals("response", actual); }
Example #20
Source File: StompBrokerRelayMessageHandlerIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
@Before public void setup() throws Exception { logger.debug("Setting up before '" + this.testName.getMethodName() + "'"); this.port = SocketUtils.findAvailableTcpPort(61613); this.responseChannel = new ExecutorSubscribableChannel(); this.responseHandler = new TestMessageHandler(); this.responseChannel.subscribe(this.responseHandler); this.eventPublisher = new TestEventPublisher(); startActiveMqBroker(); createAndStartRelay(); }
Example #21
Source File: GenericMessagingTemplateTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void sendAndReceive() { SubscribableChannel channel = new ExecutorSubscribableChannel(this.executor); channel.subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel(); replyChannel.send(new GenericMessage<>("response")); } }); String actual = this.template.convertSendAndReceive(channel, "request", String.class); assertEquals("response", actual); }
Example #22
Source File: OrderedMessageSenderTests.java From java-technology-stack with MIT License | 5 votes |
@Before public void setup() { this.executor = new ThreadPoolTaskExecutor(); this.executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2); this.executor.setAllowCoreThreadTimeOut(true); this.executor.afterPropertiesSet(); this.channel = new ExecutorSubscribableChannel(this.executor); OrderedMessageSender.configureOutboundChannel(this.channel, true); this.sender = new OrderedMessageSender(this.channel, logger); }
Example #23
Source File: StompBrokerRelayMessageHandlerIntegrationTests.java From java-technology-stack with MIT License | 5 votes |
@Before public void setup() throws Exception { logger.debug("Setting up before '" + this.testName.getMethodName() + "'"); this.port = SocketUtils.findAvailableTcpPort(61613); this.responseChannel = new ExecutorSubscribableChannel(); this.responseHandler = new TestMessageHandler(); this.responseChannel.subscribe(this.responseHandler); this.eventPublisher = new TestEventPublisher(); startActiveMqBroker(); createAndStartRelay(); }
Example #24
Source File: AbstractMessageBrokerConfiguration.java From java-technology-stack with MIT License | 5 votes |
@Bean public AbstractSubscribableChannel brokerChannel() { ChannelRegistration reg = getBrokerRegistry().getBrokerChannelRegistration(); ExecutorSubscribableChannel channel = (reg.hasTaskExecutor() ? new ExecutorSubscribableChannel(brokerChannelExecutor()) : new ExecutorSubscribableChannel()); reg.interceptors(new ImmutableMessageChannelInterceptor()); channel.setLogger(SimpLogging.forLog(channel.getLogger())); channel.setInterceptors(reg.getInterceptors()); return channel; }
Example #25
Source File: AbstractMessageBrokerConfiguration.java From java-technology-stack with MIT License | 5 votes |
@Bean public AbstractSubscribableChannel clientOutboundChannel() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientOutboundChannelExecutor()); channel.setLogger(SimpLogging.forLog(channel.getLogger())); ChannelRegistration reg = getClientOutboundChannelRegistration(); if (reg.hasInterceptors()) { channel.setInterceptors(reg.getInterceptors()); } return channel; }
Example #26
Source File: AbstractMessageBrokerConfiguration.java From java-technology-stack with MIT License | 5 votes |
@Bean public AbstractSubscribableChannel clientInboundChannel() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientInboundChannelExecutor()); channel.setLogger(SimpLogging.forLog(channel.getLogger())); ChannelRegistration reg = getClientInboundChannelRegistration(); if (reg.hasInterceptors()) { channel.setInterceptors(reg.getInterceptors()); } return channel; }
Example #27
Source File: AbstractMessageBrokerConfiguration.java From spring-analysis-note with MIT License | 5 votes |
@Bean public AbstractSubscribableChannel brokerChannel() { ChannelRegistration reg = getBrokerRegistry().getBrokerChannelRegistration(); ExecutorSubscribableChannel channel = (reg.hasTaskExecutor() ? new ExecutorSubscribableChannel(brokerChannelExecutor()) : new ExecutorSubscribableChannel()); reg.interceptors(new ImmutableMessageChannelInterceptor()); channel.setLogger(SimpLogging.forLog(channel.getLogger())); channel.setInterceptors(reg.getInterceptors()); return channel; }
Example #28
Source File: MessageBrokerConfigurationTests.java From spring-analysis-note with MIT License | 4 votes |
@Override @Bean public AbstractSubscribableChannel clientInboundChannel() { // synchronous return new ExecutorSubscribableChannel(null); }
Example #29
Source File: MessageBrokerConfigurationTests.java From spring-analysis-note with MIT License | 4 votes |
@Override @Bean public AbstractSubscribableChannel brokerChannel() { // synchronous return new ExecutorSubscribableChannel(null); }
Example #30
Source File: TestProducer.java From spring-cloud-consul with Apache License 2.0 | 4 votes |
@Bean public SubscribableChannel producerChannel() { return new ExecutorSubscribableChannel(); }