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:
Artem Bilan
2017-05-16 17:33:02 -04:00
committed by Gary Russell
parent 2b99c191f6
commit ea89682368
50 changed files with 396 additions and 267 deletions

View File

@@ -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();
}
}

View File

@@ -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);
}
}
/**

View File

@@ -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.

View File

@@ -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());
}
}
}

View File

@@ -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());
}
}
}

View File

@@ -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());
}
}
}