INT-4252 IntegrationFlow: Allow Custom Bean Names
JIRA: https://jira.spring.io/browse/INT-4252 To allow to provide arbitrary bean names for the intermediate components in the `IntegrationFlow` change `ComponentsRegistration` to return a `Map<Object, String>` instead of raw `Collection<Object>` * Use the value from that map in the `IntegrationFlowBeanPostProcessor` as a fallback option before walking into bean name generation * Provide `containerId` option for the AMQP DSL components * Revert `@AfterClass` in the `AmqpTests` * Expose `id()` for the `JmsDestinationAccessorSpec` * Register `ListenerContainer` and `JmsTemplate` as bean via `ComponentRegistration` in the particular JMS Java DSL components * Fix `Jms` factory to populate the `JmsDefaultListenerContainerSpec` for the `messageDrivenChannelAdapter()` without class specified * Refactor AMQP DSL Inbound components to deal with the new ContainerSpec API * Remove `containerId()` in favor of `id()` in the ContainerSpec
This commit is contained in:
committed by
Gary Russell
parent
2b99c191f6
commit
ea89682368
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,8 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.0.2
|
||||
*/
|
||||
public class DynamicJmsTemplate extends JmsTemplate {
|
||||
@@ -32,13 +34,13 @@ public class DynamicJmsTemplate extends JmsTemplate {
|
||||
return super.getPriority();
|
||||
}
|
||||
Assert.isTrue(priority >= 0 && priority <= 9, "JMS priority must be in the range of 0-9");
|
||||
return priority.intValue();
|
||||
return priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getReceiveTimeout() {
|
||||
Long receiveTimeout = DynamicJmsTemplateProperties.getReceiveTimeout();
|
||||
return (receiveTimeout != null) ? receiveTimeout.longValue() : super.getReceiveTimeout();
|
||||
return (receiveTimeout != null) ? receiveTimeout : super.getReceiveTimeout();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -211,10 +211,15 @@ public final class Jms {
|
||||
* @param connectionFactory the JMS ConnectionFactory to build on
|
||||
* @return the {@link JmsMessageDrivenChannelAdapterSpec} instance
|
||||
*/
|
||||
public static JmsMessageDrivenChannelAdapterSpec
|
||||
.JmsMessageDrivenChannelAdapterListenerContainerSpec<JmsDefaultListenerContainerSpec, DefaultMessageListenerContainer>
|
||||
public static JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec<JmsDefaultListenerContainerSpec, DefaultMessageListenerContainer>
|
||||
messageDrivenChannelAdapter(ConnectionFactory connectionFactory) {
|
||||
return messageDrivenChannelAdapter(connectionFactory, DefaultMessageListenerContainer.class);
|
||||
try {
|
||||
return new JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec<>(
|
||||
new JmsDefaultListenerContainerSpec().connectionFactory(connectionFactory));
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,10 +29,10 @@ import org.springframework.jms.support.destination.JmsDestinationAccessor;
|
||||
* @param <A> the target {@link JmsDestinationAccessor} implementation type.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public abstract class
|
||||
JmsDestinationAccessorSpec<S extends JmsDestinationAccessorSpec<S, A>, A extends JmsDestinationAccessor>
|
||||
public abstract class JmsDestinationAccessorSpec<S extends JmsDestinationAccessorSpec<S, A>, A extends JmsDestinationAccessor>
|
||||
extends IntegrationComponentSpec<S, A> {
|
||||
|
||||
protected JmsDestinationAccessorSpec(A accessor) {
|
||||
@@ -44,6 +44,11 @@ public abstract class
|
||||
return _this();
|
||||
}
|
||||
|
||||
@Override
|
||||
public S id(String id) {
|
||||
return super.id(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link DestinationResolver} to use.
|
||||
* @param destinationResolver the {@link DestinationResolver} to use.
|
||||
|
||||
@@ -16,11 +16,14 @@
|
||||
|
||||
package org.springframework.integration.jms.dsl;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Destination;
|
||||
|
||||
import org.springframework.integration.dsl.ComponentsRegistration;
|
||||
import org.springframework.integration.dsl.MessageSourceSpec;
|
||||
import org.springframework.integration.jms.JmsDestinationPollingSource;
|
||||
import org.springframework.integration.jms.JmsHeaderMapper;
|
||||
@@ -33,6 +36,7 @@ import org.springframework.util.Assert;
|
||||
* @param <S> the target {@link JmsInboundChannelAdapterSpec} implementation type.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public class JmsInboundChannelAdapterSpec<S extends JmsInboundChannelAdapterSpec<S>>
|
||||
@@ -92,8 +96,9 @@ public class JmsInboundChannelAdapterSpec<S extends JmsInboundChannelAdapterSpec
|
||||
/**
|
||||
* A {@link JmsTemplate}-based {@link JmsInboundChannelAdapterSpec} extension.
|
||||
*/
|
||||
public static class JmsInboundChannelSpecTemplateAware extends
|
||||
JmsInboundChannelAdapterSpec<JmsInboundChannelSpecTemplateAware> {
|
||||
public static class JmsInboundChannelSpecTemplateAware
|
||||
extends JmsInboundChannelAdapterSpec<JmsInboundChannelSpecTemplateAware>
|
||||
implements ComponentsRegistration {
|
||||
|
||||
JmsInboundChannelSpecTemplateAware(ConnectionFactory connectionFactory) {
|
||||
super(connectionFactory);
|
||||
@@ -111,6 +116,11 @@ public class JmsInboundChannelAdapterSpec<S extends JmsInboundChannelAdapterSpec
|
||||
return _this();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Object, String> getComponentsToRegister() {
|
||||
return Collections.singletonMap(this.jmsTemplateSpec.get(), this.jmsTemplateSpec.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,13 @@
|
||||
|
||||
package org.springframework.integration.jms.dsl;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.jms.Destination;
|
||||
|
||||
import org.springframework.integration.dsl.ComponentsRegistration;
|
||||
import org.springframework.integration.dsl.MessageProducerSpec;
|
||||
import org.springframework.integration.jms.ChannelPublishingJmsMessageListener;
|
||||
import org.springframework.integration.jms.JmsHeaderMapper;
|
||||
@@ -34,6 +37,7 @@ import org.springframework.util.Assert;
|
||||
* @param <S> the target {@link JmsMessageDrivenChannelAdapterSpec} implementation type.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public class JmsMessageDrivenChannelAdapterSpec<S extends JmsMessageDrivenChannelAdapterSpec<S>>
|
||||
@@ -81,7 +85,8 @@ public class JmsMessageDrivenChannelAdapterSpec<S extends JmsMessageDrivenChanne
|
||||
*/
|
||||
public static class
|
||||
JmsMessageDrivenChannelAdapterListenerContainerSpec<S extends JmsListenerContainerSpec<S, C>, C extends AbstractMessageListenerContainer>
|
||||
extends JmsMessageDrivenChannelAdapterSpec<JmsMessageDrivenChannelAdapterListenerContainerSpec<S, C>> {
|
||||
extends JmsMessageDrivenChannelAdapterSpec<JmsMessageDrivenChannelAdapterListenerContainerSpec<S, C>>
|
||||
implements ComponentsRegistration {
|
||||
|
||||
private final JmsListenerContainerSpec<S, C> spec;
|
||||
|
||||
@@ -89,6 +94,7 @@ public class JmsMessageDrivenChannelAdapterSpec<S extends JmsMessageDrivenChanne
|
||||
super(spec.get());
|
||||
this.spec = spec;
|
||||
this.spec.get().setAutoStartup(false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,6 +131,11 @@ public class JmsMessageDrivenChannelAdapterSpec<S extends JmsMessageDrivenChanne
|
||||
return _this();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Object, String> getComponentsToRegister() {
|
||||
return Collections.singletonMap(this.spec.get(), this.spec.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
|
||||
package org.springframework.integration.jms.dsl;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Destination;
|
||||
|
||||
import org.springframework.integration.dsl.ComponentsRegistration;
|
||||
import org.springframework.integration.dsl.MessageHandlerSpec;
|
||||
import org.springframework.integration.expression.FunctionExpression;
|
||||
import org.springframework.integration.jms.JmsHeaderMapper;
|
||||
@@ -127,8 +130,9 @@ public class JmsOutboundChannelAdapterSpec<S extends JmsOutboundChannelAdapterSp
|
||||
/**
|
||||
* A {@link JmsTemplate}-based {@link JmsOutboundChannelAdapterSpec} extension.
|
||||
*/
|
||||
public static class JmsOutboundChannelSpecTemplateAware extends
|
||||
JmsOutboundChannelAdapterSpec<JmsOutboundChannelSpecTemplateAware> {
|
||||
public static class JmsOutboundChannelSpecTemplateAware
|
||||
extends JmsOutboundChannelAdapterSpec<JmsOutboundChannelSpecTemplateAware>
|
||||
implements ComponentsRegistration {
|
||||
|
||||
JmsOutboundChannelSpecTemplateAware(ConnectionFactory connectionFactory) {
|
||||
super(connectionFactory);
|
||||
@@ -140,6 +144,11 @@ public class JmsOutboundChannelAdapterSpec<S extends JmsOutboundChannelAdapterSp
|
||||
return _this();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Object, String> getComponentsToRegister() {
|
||||
return Collections.singletonMap(this.jmsTemplateSpec.get(), this.jmsTemplateSpec.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -64,6 +64,7 @@ import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.jms.connection.CachingConnectionFactory;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.jms.listener.MessageListenerContainer;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
@@ -127,6 +128,17 @@ public class JmsTests {
|
||||
@Autowired
|
||||
private AtomicBoolean jmsInboundGatewayChannelCalled;
|
||||
|
||||
@Autowired(required = false)
|
||||
@Qualifier("jmsOutboundFlowTemplate")
|
||||
private JmsTemplate jmsOutboundFlowTemplate;
|
||||
|
||||
@Autowired(required = false)
|
||||
@Qualifier("jmsMessageDrivenRedeliveryFlowContainer")
|
||||
private MessageListenerContainer jmsMessageDrivenRedeliveryFlowContainer;
|
||||
|
||||
@Autowired
|
||||
private CountDownLatch redeliveryLatch;
|
||||
|
||||
@Test
|
||||
public void testPollingFlow() {
|
||||
this.controlBus.send("@'jmsTests.ContextConfiguration.integerMessageSource.inboundChannelAdapter'.start()");
|
||||
@@ -174,6 +186,8 @@ public class JmsTests {
|
||||
|
||||
assertNotNull(receive);
|
||||
assertEquals("foo", receive.getPayload());
|
||||
|
||||
assertNotNull(this.jmsOutboundFlowTemplate);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -206,9 +220,6 @@ public class JmsTests {
|
||||
assertEquals("foo", received.getPayload());
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private CountDownLatch redeliveryLatch;
|
||||
|
||||
@Test
|
||||
public void testJmsRedeliveryFlow() throws InterruptedException {
|
||||
this.jmsOutboundInboundChannel.send(MessageBuilder.withPayload("foo")
|
||||
@@ -216,6 +227,8 @@ public class JmsTests {
|
||||
.build());
|
||||
|
||||
assertTrue(this.redeliveryLatch.await(10, TimeUnit.SECONDS));
|
||||
|
||||
assertNotNull(this.jmsMessageDrivenRedeliveryFlowContainer);
|
||||
}
|
||||
|
||||
@MessagingGateway(defaultRequestChannel = "controlBus.input")
|
||||
@@ -279,8 +292,10 @@ public class JmsTests {
|
||||
|
||||
@Bean
|
||||
public IntegrationFlow jmsOutboundFlow() {
|
||||
return f -> f.handle(Jms.outboundAdapter(jmsConnectionFactory())
|
||||
.destinationExpression("headers." + SimpMessageHeaderAccessor.DESTINATION_HEADER));
|
||||
return f -> f
|
||||
.handle(Jms.outboundAdapter(jmsConnectionFactory())
|
||||
.destinationExpression("headers." + SimpMessageHeaderAccessor.DESTINATION_HEADER)
|
||||
.configureJmsTemplate(t -> t.id("jmsOutboundFlowTemplate")));
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -353,16 +368,16 @@ public class JmsTests {
|
||||
@Bean
|
||||
public IntegrationFlow jmsOutboundGatewayFlow() {
|
||||
return f -> f.handle(Jms.outboundGateway(jmsConnectionFactory())
|
||||
.replyContainer(c -> c.idleReplyContainerTimeout(10))
|
||||
.requestDestination("jmsPipelineTest"),
|
||||
.replyContainer(c -> c.idleReplyContainerTimeout(10))
|
||||
.requestDestination("jmsPipelineTest"),
|
||||
e -> e.id("jmsOutboundGateway"));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IntegrationFlow jmsInboundGatewayFlow() {
|
||||
return IntegrationFlows.from(Jms.inboundGateway(jmsConnectionFactory())
|
||||
.requestChannel(jmsInboundGatewayInputChannel())
|
||||
.destination("jmsPipelineTest"))
|
||||
.requestChannel(jmsInboundGatewayInputChannel())
|
||||
.destination("jmsPipelineTest"))
|
||||
.<String, String>transform(String::toUpperCase)
|
||||
.get();
|
||||
}
|
||||
@@ -392,7 +407,8 @@ public class JmsTests {
|
||||
return IntegrationFlows
|
||||
.from(Jms.messageDrivenChannelAdapter(jmsConnectionFactory())
|
||||
.errorChannel(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME)
|
||||
.destination("jmsMessageDrivenRedelivery"))
|
||||
.destination("jmsMessageDrivenRedelivery")
|
||||
.configureListenerContainer(c -> c.id("jmsMessageDrivenRedeliveryFlowContainer")))
|
||||
.<String, String>transform(p -> {
|
||||
throw new RuntimeException("intentional");
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user