public ScatterGatherHandler(MessageHandler scatterer, MessageHandler gatherer) { this(new FixedSubscriberChannel(scatterer), gatherer); Assert.notNull(scatterer, "'scatterer' must not be null"); Class<?> scattererClass = AopUtils.getTargetClass(scatterer); checkClass(scattererClass, "org.springframework.integration.router.RecipientListRouter", "scatterer"); }
@Override public boolean unsubscribe(MessageHandler handler) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(getComponentName() + ": cannot be unsubscribed from (it has a fixed single subscriber)."); } return false; }
@Test public void testSendPerfFixedSubscriberChannel() { /* * INT-3308 - 96 million/sec * NOTE: in order to get a measurable time, I had to add some code to the handler - * presumably the JIT compiler short circuited the call becaues it's a final field * and he knows the method does nothing. * Added the same code to the other tests for comparison. */ final AtomicInteger count = new AtomicInteger(); FixedSubscriberChannel channel = new FixedSubscriberChannel(message -> count.incrementAndGet()); GenericMessage<String> message = new GenericMessage<String>("test"); assertTrue(channel.send(message)); for (int i = 0; i < 100000000; i++) { channel.send(message, 0); } }
@SuppressWarnings("unchecked") private <S extends ConsumerEndpointSpec<S, ? extends MessageHandler>> B register(S endpointSpec, Consumer<S> endpointConfigurer) { if (endpointConfigurer != null) { endpointConfigurer.accept(endpointSpec); } MessageChannel inputChannel = this.currentMessageChannel; this.currentMessageChannel = null; if (inputChannel == null) { inputChannel = new DirectChannel(); this.registerOutputChannelIfCan(inputChannel); } Tuple2<ConsumerEndpointFactoryBean, ? extends MessageHandler> factoryBeanTuple2 = endpointSpec.get(); addComponents(endpointSpec.getComponentsToRegister()); if (inputChannel instanceof MessageChannelReference) { factoryBeanTuple2.getT1().setInputChannelName(((MessageChannelReference) inputChannel).getName()); } else { if (inputChannel instanceof FixedSubscriberChannelPrototype) { String beanName = ((FixedSubscriberChannelPrototype) inputChannel).getName(); inputChannel = new FixedSubscriberChannel(factoryBeanTuple2.getT2()); if (beanName != null) { ((FixedSubscriberChannel) inputChannel).setBeanName(beanName); } registerOutputChannelIfCan(inputChannel); } factoryBeanTuple2.getT1().setInputChannel(inputChannel); } return addComponent(endpointSpec).currentComponent(factoryBeanTuple2.getT2()); }
@Override public boolean send(Message<?> message) { return send(message, 0); }
@SuppressWarnings("unchecked") private <S extends ConsumerEndpointSpec<S, ? extends MessageHandler>> B register(S endpointSpec, Consumer<S> endpointConfigurer) { if (endpointConfigurer != null) { endpointConfigurer.accept(endpointSpec); } MessageChannel inputChannel = this.currentMessageChannel; this.currentMessageChannel = null; if (inputChannel == null) { inputChannel = new DirectChannel(); this.registerOutputChannelIfCan(inputChannel); } Tuple2<ConsumerEndpointFactoryBean, ? extends MessageHandler> factoryBeanTuple2 = endpointSpec.get(); addComponents(endpointSpec.getComponentsToRegister()); if (inputChannel instanceof MessageChannelReference) { factoryBeanTuple2.getT1().setInputChannelName(((MessageChannelReference) inputChannel).getName()); } else { if (inputChannel instanceof FixedSubscriberChannelPrototype) { String beanName = ((FixedSubscriberChannelPrototype) inputChannel).getName(); inputChannel = new FixedSubscriberChannel(factoryBeanTuple2.getT2()); if (beanName != null) { ((FixedSubscriberChannel) inputChannel).setBeanName(beanName); } registerOutputChannelIfCan(inputChannel); } factoryBeanTuple2.getT1().setInputChannel(inputChannel); } return addComponent(endpointSpec).currentComponent(factoryBeanTuple2.getT2()); }
@Override public boolean send(Message<?> message) { return this.send(message, 0); }
public WebSocketInboundChannelAdapter(IntegrationWebSocketContainer webSocketContainer, SubProtocolHandlerRegistry protocolHandlerRegistry) { Assert.notNull(webSocketContainer, "'webSocketContainer' must not be null"); Assert.notNull(protocolHandlerRegistry, "'protocolHandlerRegistry' must not be null"); this.webSocketContainer = webSocketContainer; this.server = this.webSocketContainer instanceof ServerWebSocketContainer; this.subProtocolHandlerRegistry = protocolHandlerRegistry; this.subProtocolHandlerChannel = new FixedSubscriberChannel(message -> { try { handleMessageAndSend(message); } catch (Exception e) { throw new MessageHandlingException(message, e); } }); }
private <S extends ConsumerEndpointSpec<S, ? extends MessageHandler>> B register(S endpointSpec, Consumer<S> endpointConfigurer) { if (endpointConfigurer != null) { endpointConfigurer.accept(endpointSpec); } addComponents(endpointSpec.getComponentsToRegister()); MessageChannel inputChannel = this.currentMessageChannel; this.currentMessageChannel = null; if (inputChannel == null) { inputChannel = new DirectChannel(); this.registerOutputChannelIfCan(inputChannel); } Tuple2<ConsumerEndpointFactoryBean, ? extends MessageHandler> factoryBeanTuple2 = endpointSpec.get(); if (inputChannel instanceof MessageChannelReference) { factoryBeanTuple2.getT1().setInputChannelName(((MessageChannelReference) inputChannel).getName()); } else { if (inputChannel instanceof FixedSubscriberChannelPrototype) { String beanName = ((FixedSubscriberChannelPrototype) inputChannel).getName(); inputChannel = new FixedSubscriberChannel(factoryBeanTuple2.getT2()); if (beanName != null) { ((FixedSubscriberChannel) inputChannel).setBeanName(beanName); } registerOutputChannelIfCan(inputChannel); } factoryBeanTuple2.getT1().setInputChannel(inputChannel); } return addComponent(endpointSpec).currentComponent(factoryBeanTuple2.getT2()); }
@Override public boolean subscribe(MessageHandler handler) { if (handler != this.handler && LOGGER.isDebugEnabled()) { LOGGER.debug(getComponentName() + ": cannot be subscribed to (it has a fixed single subscriber)."); } return false; }
@Test public void testContentEnricher2() { QueueChannel replyChannel = new QueueChannel(); Message<?> message = MessageBuilder.withPayload(new TestPojo("Bar")) .setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel) .build(); this.enricherInput2.send(message); Message<?> receive = replyChannel.receive(5000); assertNotNull(receive); assertNull(receive.getHeaders().get("foo")); Object payload = receive.getPayload(); assertThat(payload, instanceOf(TestPojo.class)); TestPojo result = (TestPojo) payload; assertEquals("Bar Bar", result.getName()); assertNotNull(result.getDate()); assertThat(new Date(), Matchers.greaterThanOrEqualTo(result.getDate())); }
if (flowBuilder.isOutputChannelRequired()) { registerSubflowBridge = true; flowBuilder.channel(new FixedSubscriberChannel(bridgeHandler)); routerSpec.defaultOutputChannel(new FixedSubscriberChannel(bridgeHandler)); registerSubflowBridge = true;
private <S extends ConsumerEndpointSpec<S, ? extends MessageHandler>> B register(S endpointSpec, Consumer<S> endpointConfigurer) { if (endpointConfigurer != null) { endpointConfigurer.accept(endpointSpec); } addComponents(endpointSpec.getComponentsToRegister()); MessageChannel inputChannel = this.currentMessageChannel; this.currentMessageChannel = null; if (inputChannel == null) { inputChannel = new DirectChannel(); this.registerOutputChannelIfCan(inputChannel); } Tuple2<ConsumerEndpointFactoryBean, ? extends MessageHandler> factoryBeanTuple2 = endpointSpec.get(); if (inputChannel instanceof MessageChannelReference) { factoryBeanTuple2.getT1().setInputChannelName(((MessageChannelReference) inputChannel).getName()); } else { if (inputChannel instanceof FixedSubscriberChannelPrototype) { String beanName = ((FixedSubscriberChannelPrototype) inputChannel).getName(); inputChannel = new FixedSubscriberChannel(factoryBeanTuple2.getT2()); if (beanName != null) { ((FixedSubscriberChannel) inputChannel).setBeanName(beanName); } registerOutputChannelIfCan(inputChannel); } factoryBeanTuple2.getT1().setInputChannel(inputChannel); } return addComponent(endpointSpec).currentComponent(factoryBeanTuple2.getT2()); }
String channelBeanName = fixedSubscriberChannel.getComponentName(); if ("Unnamed fixed subscriber channel".equals(channelBeanName)) { channelBeanName = flowNamePrefix + "channel" +
@Test public void testContentEnricher3() { QueueChannel replyChannel = new QueueChannel(); Message<?> message = MessageBuilder.withPayload(new TestPojo("Bar")) .setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel) .build(); this.enricherInput3.send(message); Message<?> receive = replyChannel.receive(5000); assertNotNull(receive); assertEquals("Bar Bar", receive.getHeaders().get("foo")); Object payload = receive.getPayload(); assertThat(payload, instanceOf(TestPojo.class)); TestPojo result = (TestPojo) payload; assertEquals("Bar", result.getName()); assertNull(result.getDate()); }
@Bean public RoutingSlipRouteStrategy routeStrategy() { return (requestMessage, reply) -> requestMessage.getPayload() instanceof String ? new FixedSubscriberChannel(m -> Flux.just((String) m.getPayload()) .map(String::toUpperCase) .subscribe(v -> messagingTemplate() .convertAndSend(resultsChannel(), v))) : new FixedSubscriberChannel(m -> Flux.just((Integer) m.getPayload()) .map(v -> v * 2) .subscribe(v -> messagingTemplate() .convertAndSend(resultsChannel(), v))); }
@Override public boolean subscribe(MessageHandler handler) { if (handler != this.handler && this.logger.isDebugEnabled()) { this.logger.debug(this.getComponentName() + ": cannot be subscribed to (it has a fixed single subscriber)."); } return false; }
@Test public void testContentEnricher3() { QueueChannel replyChannel = new QueueChannel(); Message<?> message = MessageBuilder.withPayload(new TestPojo("Bar")) .setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel) .build(); this.enricherInput3.send(message); Message<?> receive = replyChannel.receive(5000); assertNotNull(receive); assertEquals("Bar Bar", receive.getHeaders().get("foo")); Object payload = receive.getPayload(); assertThat(payload, instanceOf(TestPojo.class)); TestPojo result = (TestPojo) payload; assertEquals("Bar", result.getName()); assertNull(result.getDate()); }
/** * Populate a {@link WireTap} for the {@link #currentMessageChannel} * with the {@link LoggingHandler} subscriber for the provided * {@link LoggingHandler.Level} logging level, logging category * and SpEL expression for the log message. * <p> When this operator is used in the end of flow, it is treated * as one-way handler without any replies to continue. * The {@link #logAndReply()} should be used for request-reply configuration. * @param level the {@link LoggingHandler.Level}. * @param category the logging category. * @param logExpression the {@link Expression} to evaluate logger message at runtime * against the request {@link Message}. * @return the current {@link IntegrationFlowDefinition}. * @see #wireTap(WireTapSpec) */ public B log(LoggingHandler.Level level, String category, Expression logExpression) { LoggingHandler loggingHandler = new LoggingHandler(level); if (StringUtils.hasText(category)) { loggingHandler.setLoggerName(category); } if (logExpression != null) { loggingHandler.setLogExpression(logExpression); } else { loggingHandler.setShouldLogFullMessage(true); } addComponent(loggingHandler); MessageChannel loggerChannel = new FixedSubscriberChannel(loggingHandler); return wireTap(loggerChannel); }
@Override public boolean unsubscribe(MessageHandler handler) { if (this.logger.isDebugEnabled()) { this.logger.debug(this.getComponentName() + ": cannot be unsubscribed from (it has a fixed single subscriber)."); } return false; }