@Override protected void onInit() { if (consumerProperties == null || !consumerProperties.getExtension().getEnabled()) { return; } super.onInit(); if (this.retryTemplate != null) { Assert.state(getErrorChannel() == null, "Cannot have an 'errorChannel' property when a 'RetryTemplate' is " + "provided; use an 'ErrorMessageSendingRecoverer' in the 'recoveryCallback' property to " + "send an error message when retries are exhausted"); } this.consumer = consumersManager.getOrCreateConsumer(group, destination, consumerProperties); Boolean isOrderly = consumerProperties.getExtension().getOrderly(); this.listener = isOrderly ? new CloudStreamMessageListenerOrderly() : new CloudStreamMessageListenerConcurrently(); if (retryTemplate != null) { this.retryTemplate.registerListener(this.listener); } }
@Override protected void doStart() { super.doStart(); this.container.start(); }
@Override protected void doStop() { super.doStop(); this.active = false; this.listening = false; }
@Bean public MessageProducer producer() { MessageProducerSupport producer = new MessageProducerSupport() { @Override public String getComponentType() { return "test-producer"; } }; producer.setOutputChannelName("one"); producer.setErrorChannelName("myErrors"); return producer; }
private static IntegrationFlowBuilder from(MessageProducerSupport messageProducer, @Nullable IntegrationFlowBuilder integrationFlowBuilderArg) { IntegrationFlowBuilder integrationFlowBuilder = integrationFlowBuilderArg; MessageChannel outputChannel = messageProducer.getOutputChannel(); if (outputChannel == null) { outputChannel = new DirectChannel(); messageProducer.setOutputChannel(outputChannel); } if (integrationFlowBuilder == null) { integrationFlowBuilder = from(outputChannel); } else { integrationFlowBuilder.channel(outputChannel); } return integrationFlowBuilder.addComponent(messageProducer); }
@Test(expected = MessageDeliveryException.class) public void validateExceptionIfNoErrorChannel() { DirectChannel outChannel = new DirectChannel(); outChannel.subscribe(message -> { throw new RuntimeException("problems"); }); MessageProducerSupport mps = new MessageProducerSupport() { }; mps.setOutputChannel(outChannel); mps.setBeanFactory(this.context); mps.afterPropertiesSet(); mps.start(); mps.sendMessage(new GenericMessage<>("hello")); }
@Override public void setErrorChannel(MessageChannel errorChannel) { super.setErrorChannel(errorChannel); this.errorChannel = errorChannel; }
@Override protected AttributeAccessor getErrorMessageAttributes(org.springframework.messaging.Message<?> message) { AttributeAccessor attributes = attributesHolder.get(); if (attributes == null) { return super.getErrorMessageAttributes(message); } else { return attributes; } }
/** * Specify the {@code outputChannel} for the * {@link org.springframework.integration.core.MessageProducer} * @param outputChannel the outputChannel. * @return the spec. * @see MessageProducerSupport#setOutputChannel(MessageChannel) */ public S outputChannel(MessageChannel outputChannel) { this.target.setOutputChannel(outputChannel); return _this(); }
@Override public void setOutputChannelName(String outputChannelName) { super.setOutputChannelName(outputChannelName); this.listener.setRequestChannelName(outputChannelName); }
@Test public void testWithChannelName() { DirectChannel outChannel = new DirectChannel(); MessageProducerSupport mps = new MessageProducerSupport() { }; mps.setOutputChannelName("foo"); this.context.registerBean("foo", outChannel); this.context.refresh(); mps.setBeanFactory(this.context); mps.afterPropertiesSet(); mps.start(); assertSame(outChannel, mps.getOutputChannel()); }
@Override public void setErrorChannelName(String errorChannelName) { super.setErrorChannelName(errorChannelName); this.listener.setErrorChannelName(errorChannelName); }
@Test(expected = MessageDeliveryException.class) public void validateExceptionIfSendToErrorChannelFails() { DirectChannel outChannel = new DirectChannel(); outChannel.subscribe(message -> { throw new RuntimeException("problems"); }); PublishSubscribeChannel errorChannel = new PublishSubscribeChannel(); errorChannel.subscribe(message -> { throw new RuntimeException("ooops"); }); MessageProducerSupport mps = new MessageProducerSupport() { }; mps.setOutputChannel(outChannel); mps.setErrorChannel(errorChannel); mps.setBeanFactory(this.context); mps.afterPropertiesSet(); mps.start(); mps.sendMessage(new GenericMessage<>("hello")); }
/** * Configure the {@link MessageChannel} to which error messages will be sent. * @param errorChannel the errorChannel. * @return the spec. * @see MessageProducerSupport#setErrorChannel(MessageChannel) */ public S errorChannel(MessageChannel errorChannel) { this.target.setErrorChannel(errorChannel); return _this(); }
private static IntegrationFlowBuilder from(MessageProducerSupport messageProducer, @Nullable IntegrationFlowBuilder integrationFlowBuilderArg) { IntegrationFlowBuilder integrationFlowBuilder = integrationFlowBuilderArg; MessageChannel outputChannel = messageProducer.getOutputChannel(); if (outputChannel == null) { outputChannel = new DirectChannel(); messageProducer.setOutputChannel(outputChannel); } if (integrationFlowBuilder == null) { integrationFlowBuilder = from(outputChannel); } else { integrationFlowBuilder.channel(outputChannel); } return integrationFlowBuilder.addComponent(messageProducer); }
/** * Build an error message for the exception and message using the configured * {@link ErrorMessageStrategy}. * @param message the message. * @param exception the exception. * @return the error message. * @since 4.3.10 */ protected final ErrorMessage buildErrorMessage(Message<?> message, RuntimeException exception) { return this.errorMessageStrategy.buildErrorMessage(exception, getErrorMessageAttributes(message)); }
@Override public void setOutputChannel(MessageChannel outputChannel) { super.setOutputChannel(outputChannel); this.listener.setRequestChannel(outputChannel); }
/** * Specify the bean name of the {@code outputChannel} for the * {@link org.springframework.integration.core.MessageProducer} * @param outputChannel the outputChannel bean name. * @return the spec. * @see MessageProducerSupport#setOutputChannelName(String) */ public S outputChannel(String outputChannel) { this.target.setOutputChannelName(outputChannel); return _this(); }
/** * Configure the bean name of the {@link MessageChannel} to which error messages will be sent. * @param errorChannel the errorChannel bean name. * @return the spec. * @see MessageProducerSupport#setErrorChannelName(String) */ public S errorChannel(String errorChannel) { this.target.setErrorChannelName(errorChannel); return _this(); }
@Override protected void onInit() { super.onInit(); if (this.isClientMode) { Assert.notNull(this.clientConnectionFactory, "For client-mode, connection factory must be type='client'"); Assert.isTrue(!this.clientConnectionFactory.isSingleUse(), "For client-mode, connection factory must have single-use='false'"); } }