org.springframework.jms.listener.endpoint.JmsMessageEndpointManager Java Examples

The following examples show how to use org.springframework.jms.listener.endpoint.JmsMessageEndpointManager. 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: JmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void setupJcaMessageContainerFullConfig() {
	JmsMessageEndpointManager container = new JmsMessageEndpointManager();
	MessageListener messageListener = new MessageListenerAdapter();
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	endpoint.setDestination("myQueue");
	endpoint.setSelector("foo = 'bar'");
	endpoint.setSubscription("mySubscription");
	endpoint.setConcurrency("10");
	endpoint.setMessageListener(messageListener);

	endpoint.setupListenerContainer(container);
	JmsActivationSpecConfig config = container.getActivationSpecConfig();
	assertEquals("myQueue", config.getDestinationName());
	assertEquals("foo = 'bar'", config.getMessageSelector());
	assertEquals("mySubscription", config.getSubscriptionName());
	assertEquals(10, config.getMaxConcurrency());
	assertEquals(messageListener, container.getMessageListener());
}
 
Example #2
Source File: JmsListenerEndpointTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void setupJcaMessageContainerFullConfig() {
	JmsMessageEndpointManager container = new JmsMessageEndpointManager();
	MessageListener messageListener = new MessageListenerAdapter();
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	endpoint.setDestination("myQueue");
	endpoint.setSelector("foo = 'bar'");
	endpoint.setSubscription("mySubscription");
	endpoint.setConcurrency("10");
	endpoint.setMessageListener(messageListener);

	endpoint.setupListenerContainer(container);
	JmsActivationSpecConfig config = container.getActivationSpecConfig();
	assertEquals("myQueue", config.getDestinationName());
	assertEquals("foo = 'bar'", config.getMessageSelector());
	assertEquals("mySubscription", config.getSubscriptionName());
	assertEquals(10, config.getMaxConcurrency());
	assertEquals(messageListener, container.getMessageListener());
}
 
Example #3
Source File: JmsNamespaceHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testComponentRegistration() {
	assertTrue("Parser should have registered a component named 'listener1'",
			context.containsComponentDefinition("listener1"));
	assertTrue("Parser should have registered a component named 'listener2'",
			context.containsComponentDefinition("listener2"));
	assertTrue("Parser should have registered a component named 'listener3'",
			context.containsComponentDefinition("listener3"));
	assertTrue("Parser should have registered a component named '"
			+ DefaultMessageListenerContainer.class.getName() + "#0'",
			context.containsComponentDefinition(DefaultMessageListenerContainer.class.getName() + "#0"));
	assertTrue("Parser should have registered a component named '"
			+ JmsMessageEndpointManager.class.getName() + "#0'",
			context.containsComponentDefinition(JmsMessageEndpointManager.class.getName() + "#0"));
	assertTrue("Parser should have registered a component named 'testJmsFactory",
			context.containsComponentDefinition("testJmsFactory"));
	assertTrue("Parser should have registered a component named 'testJcaFactory",
			context.containsComponentDefinition("testJcaFactory"));
	assertTrue("Parser should have registered a component named 'testJcaFactory",
			context.containsComponentDefinition("onlyJmsFactory"));
}
 
Example #4
Source File: JmsNamespaceHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testResponseDestination() {
	// JMS
	DefaultMessageListenerContainer listener1 = this.context
			.getBean("listener1", DefaultMessageListenerContainer.class);
	DefaultMessageListenerContainer listener2 = this.context
			.getBean("listener2", DefaultMessageListenerContainer.class);
	assertEquals("Wrong destination type on listener1", true, listener1.isPubSubDomain());
	assertEquals("Wrong destination type on listener2", true, listener2.isPubSubDomain());
	assertEquals("Wrong response destination type on listener1", false, listener1.isReplyPubSubDomain());
	assertEquals("Wrong response destination type on listener2", false, listener2.isReplyPubSubDomain());

	// JCA
	JmsMessageEndpointManager listener3 = this.context
			.getBean("listener3", JmsMessageEndpointManager.class);
	JmsMessageEndpointManager listener4 = this.context
			.getBean("listener4", JmsMessageEndpointManager.class);
	assertEquals("Wrong destination type on listener3", true, listener3.isPubSubDomain());
	assertEquals("Wrong destination type on listener4", true, listener4.isPubSubDomain());
	assertEquals("Wrong response destination type on listener3", false, listener3.isReplyPubSubDomain());
	assertEquals("Wrong response destination type on listener4", false, listener4.isReplyPubSubDomain());
}
 
Example #5
Source File: JmsNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testJcaContainerFactoryConfiguration() {
	Map<String, DefaultJcaListenerContainerFactory> containers =
			context.getBeansOfType(DefaultJcaListenerContainerFactory.class);
	DefaultJcaListenerContainerFactory factory = containers.get("testJcaFactory");
	assertNotNull("No factory registered with testJcaFactory id", factory);

	JmsMessageEndpointManager container =
			factory.createListenerContainer(createDummyEndpoint());
	assertEquals("explicit resource adapter not set",
			context.getBean("testResourceAdapter"),container.getResourceAdapter());
	assertEquals("explicit message converter not set",
			context.getBean("testMessageConverter"), container.getActivationSpecConfig().getMessageConverter());
	assertEquals("Wrong pub/sub", true, container.isPubSubDomain());
	assertEquals("wrong concurrency", 5, container.getActivationSpecConfig().getMaxConcurrency());
	assertEquals("Wrong prefetch", 50, container.getActivationSpecConfig().getPrefetchSize());
	assertEquals("Wrong phase", 77, container.getPhase());
}
 
Example #6
Source File: JmsNamespaceHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testJcaContainerFactoryConfiguration() {
	Map<String, DefaultJcaListenerContainerFactory> containers =
			context.getBeansOfType(DefaultJcaListenerContainerFactory.class);
	DefaultJcaListenerContainerFactory factory = containers.get("testJcaFactory");
	assertNotNull("No factory registered with testJcaFactory id", factory);

	JmsMessageEndpointManager container =
			factory.createListenerContainer(createDummyEndpoint());
	assertEquals("explicit resource adapter not set",
			context.getBean("testResourceAdapter"),container.getResourceAdapter());
	assertEquals("explicit message converter not set",
			context.getBean("testMessageConverter"), container.getActivationSpecConfig().getMessageConverter());
	assertEquals("Wrong pub/sub", true, container.isPubSubDomain());
	assertEquals("wrong concurrency", 5, container.getActivationSpecConfig().getMaxConcurrency());
	assertEquals("Wrong prefetch", 50, container.getActivationSpecConfig().getPrefetchSize());
	assertEquals("Wrong phase", 77, container.getPhase());
}
 
Example #7
Source File: JmsNamespaceHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testJcaContainerConfiguration() throws Exception {
	Map<String, JmsMessageEndpointManager> containers = context.getBeansOfType(JmsMessageEndpointManager.class);

	assertTrue("listener3 not found", containers.containsKey("listener3"));
	JmsMessageEndpointManager listener3 = containers.get("listener3");
	assertEquals("Wrong resource adapter",
			context.getBean("testResourceAdapter"), listener3.getResourceAdapter());
	assertEquals("Wrong activation spec factory", context.getBean("testActivationSpecFactory"),
			new DirectFieldAccessor(listener3).getPropertyValue("activationSpecFactory"));


	Object endpointFactory = new DirectFieldAccessor(listener3).getPropertyValue("endpointFactory");
	Object messageListener = new DirectFieldAccessor(endpointFactory).getPropertyValue("messageListener");
	assertEquals("Wrong message listener", MessageListenerAdapter.class, messageListener.getClass());
	MessageListenerAdapter adapter = (MessageListenerAdapter) messageListener;
	DirectFieldAccessor adapterFieldAccessor = new DirectFieldAccessor(adapter);
	assertEquals("Message converter not set properly", context.getBean("testMessageConverter"),
			adapterFieldAccessor.getPropertyValue("messageConverter"));
	assertEquals("Wrong delegate", context.getBean("testBean1"),
			adapterFieldAccessor.getPropertyValue("delegate"));
	assertEquals("Wrong method name", "setName",
			adapterFieldAccessor.getPropertyValue("defaultListenerMethod"));
}
 
Example #8
Source File: JmsListenerContainerFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void createJcaContainerFullConfig() {
	DefaultJcaListenerContainerFactory factory = new DefaultJcaListenerContainerFactory();
	setDefaultJcaConfig(factory);
	factory.setConcurrency("10");

	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	endpoint.setDestination("myQueue");
	JmsMessageEndpointManager container = factory.createListenerContainer(endpoint);

	assertDefaultJcaConfig(container);
	assertEquals(10, container.getActivationSpecConfig().getMaxConcurrency());
	assertEquals(messageListener, container.getMessageListener());
	assertEquals("myQueue", container.getActivationSpecConfig().getDestinationName());
}
 
Example #9
Source File: JmsNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testResponseDestination() {
	// JMS
	DefaultMessageListenerContainer listener1 = this.context
			.getBean("listener1", DefaultMessageListenerContainer.class);
	DefaultMessageListenerContainer listener2 = this.context
			.getBean("listener2", DefaultMessageListenerContainer.class);
	assertEquals("Wrong destination type on listener1", true, listener1.isPubSubDomain());
	assertEquals("Wrong destination type on listener2", true, listener2.isPubSubDomain());
	assertEquals("Wrong response destination type on listener1", false, listener1.isReplyPubSubDomain());
	assertEquals("Wrong response destination type on listener2", false, listener2.isReplyPubSubDomain());

	// JCA
	JmsMessageEndpointManager listener3 = this.context
			.getBean("listener3", JmsMessageEndpointManager.class);
	JmsMessageEndpointManager listener4 = this.context
			.getBean("listener4", JmsMessageEndpointManager.class);
	assertEquals("Wrong destination type on listener3", true, listener3.isPubSubDomain());
	assertEquals("Wrong destination type on listener4", true, listener4.isPubSubDomain());
	assertEquals("Wrong response destination type on listener3", false, listener3.isReplyPubSubDomain());
	assertEquals("Wrong response destination type on listener4", false, listener4.isReplyPubSubDomain());
}
 
Example #10
Source File: JmsNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testComponentRegistration() {
	assertTrue("Parser should have registered a component named 'listener1'",
			context.containsComponentDefinition("listener1"));
	assertTrue("Parser should have registered a component named 'listener2'",
			context.containsComponentDefinition("listener2"));
	assertTrue("Parser should have registered a component named 'listener3'",
			context.containsComponentDefinition("listener3"));
	assertTrue("Parser should have registered a component named '"
			+ DefaultMessageListenerContainer.class.getName() + "#0'",
			context.containsComponentDefinition(DefaultMessageListenerContainer.class.getName() + "#0"));
	assertTrue("Parser should have registered a component named '"
			+ JmsMessageEndpointManager.class.getName() + "#0'",
			context.containsComponentDefinition(JmsMessageEndpointManager.class.getName() + "#0"));
	assertTrue("Parser should have registered a component named 'testJmsFactory",
			context.containsComponentDefinition("testJmsFactory"));
	assertTrue("Parser should have registered a component named 'testJcaFactory",
			context.containsComponentDefinition("testJcaFactory"));
	assertTrue("Parser should have registered a component named 'testJcaFactory",
			context.containsComponentDefinition("onlyJmsFactory"));
}
 
Example #11
Source File: JmsListenerContainerFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void createJcaContainerFullConfig() {
	DefaultJcaListenerContainerFactory factory = new DefaultJcaListenerContainerFactory();
	setDefaultJcaConfig(factory);
	factory.setConcurrency("10");

	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	endpoint.setDestination("myQueue");
	JmsMessageEndpointManager container = factory.createListenerContainer(endpoint);

	assertDefaultJcaConfig(container);
	assertEquals(10, container.getActivationSpecConfig().getMaxConcurrency());
	assertEquals(messageListener, container.getMessageListener());
	assertEquals("myQueue", container.getActivationSpecConfig().getDestinationName());
}
 
Example #12
Source File: JmsListenerEndpointTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void setupJcaMessageContainerFullConfig() {
	JmsMessageEndpointManager container = new JmsMessageEndpointManager();
	MessageListener messageListener = new MessageListenerAdapter();
	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	endpoint.setDestination("myQueue");
	endpoint.setSelector("foo = 'bar'");
	endpoint.setSubscription("mySubscription");
	endpoint.setConcurrency("10");
	endpoint.setMessageListener(messageListener);

	endpoint.setupListenerContainer(container);
	JmsActivationSpecConfig config = container.getActivationSpecConfig();
	assertEquals("myQueue", config.getDestinationName());
	assertEquals("foo = 'bar'", config.getMessageSelector());
	assertEquals("mySubscription", config.getSubscriptionName());
	assertEquals(10, config.getMaxConcurrency());
	assertEquals(messageListener, container.getMessageListener());
}
 
Example #13
Source File: JmsNamespaceHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testComponentRegistration() {
	assertTrue("Parser should have registered a component named 'listener1'",
			context.containsComponentDefinition("listener1"));
	assertTrue("Parser should have registered a component named 'listener2'",
			context.containsComponentDefinition("listener2"));
	assertTrue("Parser should have registered a component named 'listener3'",
			context.containsComponentDefinition("listener3"));
	assertTrue("Parser should have registered a component named '"
			+ DefaultMessageListenerContainer.class.getName() + "#0'",
			context.containsComponentDefinition(DefaultMessageListenerContainer.class.getName() + "#0"));
	assertTrue("Parser should have registered a component named '"
			+ JmsMessageEndpointManager.class.getName() + "#0'",
			context.containsComponentDefinition(JmsMessageEndpointManager.class.getName() + "#0"));
	assertTrue("Parser should have registered a component named 'testJmsFactory",
			context.containsComponentDefinition("testJmsFactory"));
	assertTrue("Parser should have registered a component named 'testJcaFactory",
			context.containsComponentDefinition("testJcaFactory"));
	assertTrue("Parser should have registered a component named 'testJcaFactory",
			context.containsComponentDefinition("onlyJmsFactory"));
}
 
Example #14
Source File: JmsNamespaceHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testResponseDestination() {
	// JMS
	DefaultMessageListenerContainer listener1 = this.context
			.getBean("listener1", DefaultMessageListenerContainer.class);
	DefaultMessageListenerContainer listener2 = this.context
			.getBean("listener2", DefaultMessageListenerContainer.class);
	assertEquals("Wrong destination type on listener1", true, listener1.isPubSubDomain());
	assertEquals("Wrong destination type on listener2", true, listener2.isPubSubDomain());
	assertEquals("Wrong response destination type on listener1", false, listener1.isReplyPubSubDomain());
	assertEquals("Wrong response destination type on listener2", false, listener2.isReplyPubSubDomain());

	// JCA
	JmsMessageEndpointManager listener3 = this.context
			.getBean("listener3", JmsMessageEndpointManager.class);
	JmsMessageEndpointManager listener4 = this.context
			.getBean("listener4", JmsMessageEndpointManager.class);
	assertEquals("Wrong destination type on listener3", true, listener3.isPubSubDomain());
	assertEquals("Wrong destination type on listener4", true, listener4.isPubSubDomain());
	assertEquals("Wrong response destination type on listener3", false, listener3.isReplyPubSubDomain());
	assertEquals("Wrong response destination type on listener4", false, listener4.isReplyPubSubDomain());
}
 
Example #15
Source File: JmsListenerContainerFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void createJcaContainerFullConfig() {
	DefaultJcaListenerContainerFactory factory = new DefaultJcaListenerContainerFactory();
	setDefaultJcaConfig(factory);
	factory.setConcurrency("10");

	SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
	MessageListener messageListener = new MessageListenerAdapter();
	endpoint.setMessageListener(messageListener);
	endpoint.setDestination("myQueue");
	JmsMessageEndpointManager container = factory.createListenerContainer(endpoint);

	assertDefaultJcaConfig(container);
	assertEquals(10, container.getActivationSpecConfig().getMaxConcurrency());
	assertEquals(messageListener, container.getMessageListener());
	assertEquals("myQueue", container.getActivationSpecConfig().getDestinationName());
}
 
Example #16
Source File: JmsNamespaceHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testJcaContainerFactoryConfiguration() {
	Map<String, DefaultJcaListenerContainerFactory> containers =
			context.getBeansOfType(DefaultJcaListenerContainerFactory.class);
	DefaultJcaListenerContainerFactory factory = containers.get("testJcaFactory");
	assertNotNull("No factory registered with testJcaFactory id", factory);

	JmsMessageEndpointManager container =
			factory.createListenerContainer(createDummyEndpoint());
	assertEquals("explicit resource adapter not set",
			context.getBean("testResourceAdapter"),container.getResourceAdapter());
	assertEquals("explicit message converter not set",
			context.getBean("testMessageConverter"), container.getActivationSpecConfig().getMessageConverter());
	assertEquals("Wrong pub/sub", true, container.isPubSubDomain());
	assertEquals("wrong concurrency", 5, container.getActivationSpecConfig().getMaxConcurrency());
	assertEquals("Wrong prefetch", 50, container.getActivationSpecConfig().getPrefetchSize());
	assertEquals("Wrong phase", 77, container.getPhase());
}
 
Example #17
Source File: JmsNamespaceHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testJcaContainerConfiguration() throws Exception {
	Map<String, JmsMessageEndpointManager> containers = context.getBeansOfType(JmsMessageEndpointManager.class);

	assertTrue("listener3 not found", containers.containsKey("listener3"));
	JmsMessageEndpointManager listener3 = containers.get("listener3");
	assertEquals("Wrong resource adapter",
			context.getBean("testResourceAdapter"), listener3.getResourceAdapter());
	assertEquals("Wrong activation spec factory", context.getBean("testActivationSpecFactory"),
			new DirectFieldAccessor(listener3).getPropertyValue("activationSpecFactory"));


	Object endpointFactory = new DirectFieldAccessor(listener3).getPropertyValue("endpointFactory");
	Object messageListener = new DirectFieldAccessor(endpointFactory).getPropertyValue("messageListener");
	assertEquals("Wrong message listener", MessageListenerAdapter.class, messageListener.getClass());
	MessageListenerAdapter adapter = (MessageListenerAdapter) messageListener;
	DirectFieldAccessor adapterFieldAccessor = new DirectFieldAccessor(adapter);
	assertEquals("Message converter not set properly", context.getBean("testMessageConverter"),
			adapterFieldAccessor.getPropertyValue("messageConverter"));
	assertEquals("Wrong delegate", context.getBean("testBean1"),
			adapterFieldAccessor.getPropertyValue("delegate"));
	assertEquals("Wrong method name", "setName",
			adapterFieldAccessor.getPropertyValue("defaultListenerMethod"));
}
 
Example #18
Source File: JmsNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testJcaContainerConfiguration() throws Exception {
	Map<String, JmsMessageEndpointManager> containers = context.getBeansOfType(JmsMessageEndpointManager.class);

	assertTrue("listener3 not found", containers.containsKey("listener3"));
	JmsMessageEndpointManager listener3 = containers.get("listener3");
	assertEquals("Wrong resource adapter",
			context.getBean("testResourceAdapter"), listener3.getResourceAdapter());
	assertEquals("Wrong activation spec factory", context.getBean("testActivationSpecFactory"),
			new DirectFieldAccessor(listener3).getPropertyValue("activationSpecFactory"));


	Object endpointFactory = new DirectFieldAccessor(listener3).getPropertyValue("endpointFactory");
	Object messageListener = new DirectFieldAccessor(endpointFactory).getPropertyValue("messageListener");
	assertEquals("Wrong message listener", MessageListenerAdapter.class, messageListener.getClass());
	MessageListenerAdapter adapter = (MessageListenerAdapter) messageListener;
	DirectFieldAccessor adapterFieldAccessor = new DirectFieldAccessor(adapter);
	assertEquals("Message converter not set properly", context.getBean("testMessageConverter"),
			adapterFieldAccessor.getPropertyValue("messageConverter"));
	assertEquals("Wrong delegate", context.getBean("testBean1"),
			adapterFieldAccessor.getPropertyValue("delegate"));
	assertEquals("Wrong method name", "setName",
			adapterFieldAccessor.getPropertyValue("defaultListenerMethod"));
}
 
Example #19
Source File: AbstractJmsListenerEndpoint.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public void configureEndpoint(Object listenerContainer) {
	if (listenerContainer instanceof JmsMessageEndpointManager) {
		setupJcaMessageContainer((JmsMessageEndpointManager) listenerContainer);
	}
	else {
		throw new IllegalArgumentException("Could not configure endpoint with the specified container '" +
				listenerContainer + "' Only JMS (" + AbstractMessageListenerContainer.class.getName() +
				" subclass) or JCA (" + JmsMessageEndpointManager.class.getName() + ") are supported.");
	}
}
 
Example #20
Source File: TracingConnectionFactoryBeanPostProcessor.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
		throws BeansException {
	// Wrap the caching connection factories instead of its target, because it catches
	// callbacks
	// such as ExceptionListener. If we don't wrap, cached callbacks like this won't
	// be traced.
	if (bean instanceof CachingConnectionFactory) {
		return new LazyConnectionFactory(this.beanFactory,
				(CachingConnectionFactory) bean);
	}
	if (bean instanceof JmsMessageEndpointManager) {
		JmsMessageEndpointManager manager = (JmsMessageEndpointManager) bean;
		MessageListener listener = manager.getMessageListener();
		if (listener != null) {
			manager.setMessageListener(
					new LazyMessageListener(this.beanFactory, listener));
		}
		return bean;
	}
	if (bean instanceof XAConnectionFactory && bean instanceof ConnectionFactory) {
		return new LazyConnectionAndXaConnectionFactory(this.beanFactory,
				(ConnectionFactory) bean, (XAConnectionFactory) bean);
	}
	// We check XA first in case the ConnectionFactory also implements
	// XAConnectionFactory
	else if (bean instanceof XAConnectionFactory) {
		return new LazyXAConnectionFactory(this.beanFactory,
				(XAConnectionFactory) bean);
	}
	else if (bean instanceof TopicConnectionFactory) {
		return new LazyTopicConnectionFactory(this.beanFactory,
				(TopicConnectionFactory) bean);
	}
	else if (bean instanceof ConnectionFactory) {
		return new LazyConnectionFactory(this.beanFactory, (ConnectionFactory) bean);
	}
	return bean;
}
 
Example #21
Source File: JmsNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testConcurrency() {
	// JMS
	DefaultMessageListenerContainer listener0 = this.context
			.getBean(DefaultMessageListenerContainer.class.getName() + "#0", DefaultMessageListenerContainer.class);
	DefaultMessageListenerContainer listener1 = this.context
			.getBean("listener1", DefaultMessageListenerContainer.class);
	DefaultMessageListenerContainer listener2 = this.context
			.getBean("listener2", DefaultMessageListenerContainer.class);

	assertEquals("Wrong concurrency on listener using placeholder", 2, listener0.getConcurrentConsumers());
	assertEquals("Wrong concurrency on listener using placeholder", 3, listener0.getMaxConcurrentConsumers());
	assertEquals("Wrong concurrency on listener1", 3, listener1.getConcurrentConsumers());
	assertEquals("Wrong max concurrency on listener1", 5, listener1.getMaxConcurrentConsumers());
	assertEquals("Wrong custom concurrency on listener2", 5, listener2.getConcurrentConsumers());
	assertEquals("Wrong custom max concurrency on listener2", 10, listener2.getMaxConcurrentConsumers());

	// JCA
	JmsMessageEndpointManager listener3 = this.context
			.getBean("listener3", JmsMessageEndpointManager.class);
	JmsMessageEndpointManager listener4 = this.context
			.getBean("listener4", JmsMessageEndpointManager.class);
	assertEquals("Wrong concurrency on listener3", 5,
			listener3.getActivationSpecConfig().getMaxConcurrency());
	assertEquals("Wrong custom concurrency on listener4", 7,
			listener4.getActivationSpecConfig().getMaxConcurrency());
}
 
Example #22
Source File: JmsListenerContainerFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void assertDefaultJcaConfig(JmsMessageEndpointManager container) {
	assertEquals(messageConverter, container.getMessageConverter());
	assertEquals(destinationResolver, container.getDestinationResolver());
	JmsActivationSpecConfig config = container.getActivationSpecConfig();
	assertNotNull(config);
	assertEquals(Session.DUPS_OK_ACKNOWLEDGE, config.getAcknowledgeMode());
	assertEquals(true, config.isPubSubDomain());
	assertEquals(true, config.isSubscriptionDurable());
	assertEquals("client-1234", config.getClientId());
}
 
Example #23
Source File: DefaultJcaListenerContainerFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public JmsMessageEndpointManager createListenerContainer(JmsListenerEndpoint endpoint) {
	if (this.destinationResolver != null && this.activationSpecFactory != null) {
		throw new IllegalStateException("Specify either 'activationSpecFactory' or " +
				"'destinationResolver', not both. If you define a dedicated JmsActivationSpecFactory bean, " +
				"specify the custom DestinationResolver there (if possible)");
	}

	JmsMessageEndpointManager instance = createContainerInstance();

	if (this.resourceAdapter != null) {
		instance.setResourceAdapter(this.resourceAdapter);
	}
	if (this.activationSpecFactory != null) {
		instance.setActivationSpecFactory(this.activationSpecFactory);
	}
	if (this.destinationResolver != null) {
		instance.setDestinationResolver(this.destinationResolver);
	}
	if (this.transactionManager != null) {
		instance.setTransactionManager(this.transactionManager);
	}
	if (this.phase != null) {
		instance.setPhase(this.phase);
	}

	instance.setActivationSpecConfig(this);
	endpoint.setupListenerContainer(instance);

	return instance;
}
 
Example #24
Source File: DefaultJcaListenerContainerFactory.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public JmsMessageEndpointManager createListenerContainer(JmsListenerEndpoint endpoint) {
	if (this.destinationResolver != null && this.activationSpecFactory != null) {
		throw new IllegalStateException("Specify either 'activationSpecFactory' or " +
				"'destinationResolver', not both. If you define a dedicated JmsActivationSpecFactory bean, " +
				"specify the custom DestinationResolver there (if possible)");
	}

	JmsMessageEndpointManager instance = createContainerInstance();

	if (this.resourceAdapter != null) {
		instance.setResourceAdapter(this.resourceAdapter);
	}
	if (this.activationSpecFactory != null) {
		instance.setActivationSpecFactory(this.activationSpecFactory);
	}
	if (this.destinationResolver != null) {
		instance.setDestinationResolver(this.destinationResolver);
	}
	if (this.transactionManager != null) {
		instance.setTransactionManager(this.transactionManager);
	}
	if (this.phase != null) {
		instance.setPhase(this.phase);
	}

	instance.setActivationSpecConfig(this);
	endpoint.setupListenerContainer(instance);

	return instance;
}
 
Example #25
Source File: JmsListenerContainerFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void assertDefaultJcaConfig(JmsMessageEndpointManager container) {
	assertEquals(this.messageConverter, container.getMessageConverter());
	assertEquals(this.destinationResolver, container.getDestinationResolver());
	JmsActivationSpecConfig config = container.getActivationSpecConfig();
	assertNotNull(config);
	assertEquals(Session.DUPS_OK_ACKNOWLEDGE, config.getAcknowledgeMode());
	assertEquals(true, config.isPubSubDomain());
	assertEquals(new QosSettings(1, 7, 5000), container.getReplyQosSettings());
	assertEquals(true, config.isSubscriptionDurable());
	assertEquals("client-1234", config.getClientId());
}
 
Example #26
Source File: JmsNamespaceHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testConcurrency() {
	// JMS
	DefaultMessageListenerContainer listener0 = this.context
			.getBean(DefaultMessageListenerContainer.class.getName() + "#0", DefaultMessageListenerContainer.class);
	DefaultMessageListenerContainer listener1 = this.context
			.getBean("listener1", DefaultMessageListenerContainer.class);
	DefaultMessageListenerContainer listener2 = this.context
			.getBean("listener2", DefaultMessageListenerContainer.class);

	assertEquals("Wrong concurrency on listener using placeholder", 2, listener0.getConcurrentConsumers());
	assertEquals("Wrong concurrency on listener using placeholder", 3, listener0.getMaxConcurrentConsumers());
	assertEquals("Wrong concurrency on listener1", 3, listener1.getConcurrentConsumers());
	assertEquals("Wrong max concurrency on listener1", 5, listener1.getMaxConcurrentConsumers());
	assertEquals("Wrong custom concurrency on listener2", 5, listener2.getConcurrentConsumers());
	assertEquals("Wrong custom max concurrency on listener2", 10, listener2.getMaxConcurrentConsumers());

	// JCA
	JmsMessageEndpointManager listener3 = this.context
			.getBean("listener3", JmsMessageEndpointManager.class);
	JmsMessageEndpointManager listener4 = this.context
			.getBean("listener4", JmsMessageEndpointManager.class);
	assertEquals("Wrong concurrency on listener3", 5,
			listener3.getActivationSpecConfig().getMaxConcurrency());
	assertEquals("Wrong custom concurrency on listener4", 7,
			listener4.getActivationSpecConfig().getMaxConcurrency());
}
 
Example #27
Source File: AbstractJmsListenerEndpoint.java    From java-technology-stack with MIT License 5 votes vote down vote up
public void configureEndpoint(Object listenerContainer) {
	if (listenerContainer instanceof JmsMessageEndpointManager) {
		setupJcaMessageContainer((JmsMessageEndpointManager) listenerContainer);
	}
	else {
		throw new IllegalArgumentException("Could not configure endpoint with the specified container '" +
				listenerContainer + "' Only JMS (" + AbstractMessageListenerContainer.class.getName() +
				" subclass) or JCA (" + JmsMessageEndpointManager.class.getName() + ") are supported.");
	}
}
 
Example #28
Source File: DefaultJcaListenerContainerFactory.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public JmsMessageEndpointManager createListenerContainer(JmsListenerEndpoint endpoint) {
	if (this.destinationResolver != null && this.activationSpecFactory != null) {
		throw new IllegalStateException("Specify either 'activationSpecFactory' or " +
				"'destinationResolver', not both. If you define a dedicated JmsActivationSpecFactory bean, " +
				"specify the custom DestinationResolver there (if possible)");
	}

	JmsMessageEndpointManager instance = createContainerInstance();

	if (this.resourceAdapter != null) {
		instance.setResourceAdapter(this.resourceAdapter);
	}
	if (this.activationSpecFactory != null) {
		instance.setActivationSpecFactory(this.activationSpecFactory);
	}
	if (this.destinationResolver != null) {
		instance.setDestinationResolver(this.destinationResolver);
	}
	if (this.transactionManager != null) {
		instance.setTransactionManager(this.transactionManager);
	}
	if (this.phase != null) {
		instance.setPhase(this.phase);
	}

	instance.setActivationSpecConfig(this);
	endpoint.setupListenerContainer(instance);

	return instance;
}
 
Example #29
Source File: JmsListenerContainerFactoryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void assertDefaultJcaConfig(JmsMessageEndpointManager container) {
	assertEquals(this.messageConverter, container.getMessageConverter());
	assertEquals(this.destinationResolver, container.getDestinationResolver());
	JmsActivationSpecConfig config = container.getActivationSpecConfig();
	assertNotNull(config);
	assertEquals(Session.DUPS_OK_ACKNOWLEDGE, config.getAcknowledgeMode());
	assertEquals(true, config.isPubSubDomain());
	assertEquals(new QosSettings(1, 7, 5000), container.getReplyQosSettings());
	assertEquals(true, config.isSubscriptionDurable());
	assertEquals("client-1234", config.getClientId());
}
 
Example #30
Source File: JmsNamespaceHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testConcurrency() {
	// JMS
	DefaultMessageListenerContainer listener0 = this.context
			.getBean(DefaultMessageListenerContainer.class.getName() + "#0", DefaultMessageListenerContainer.class);
	DefaultMessageListenerContainer listener1 = this.context
			.getBean("listener1", DefaultMessageListenerContainer.class);
	DefaultMessageListenerContainer listener2 = this.context
			.getBean("listener2", DefaultMessageListenerContainer.class);

	assertEquals("Wrong concurrency on listener using placeholder", 2, listener0.getConcurrentConsumers());
	assertEquals("Wrong concurrency on listener using placeholder", 3, listener0.getMaxConcurrentConsumers());
	assertEquals("Wrong concurrency on listener1", 3, listener1.getConcurrentConsumers());
	assertEquals("Wrong max concurrency on listener1", 5, listener1.getMaxConcurrentConsumers());
	assertEquals("Wrong custom concurrency on listener2", 5, listener2.getConcurrentConsumers());
	assertEquals("Wrong custom max concurrency on listener2", 10, listener2.getMaxConcurrentConsumers());

	// JCA
	JmsMessageEndpointManager listener3 = this.context
			.getBean("listener3", JmsMessageEndpointManager.class);
	JmsMessageEndpointManager listener4 = this.context
			.getBean("listener4", JmsMessageEndpointManager.class);
	assertEquals("Wrong concurrency on listener3", 5,
			listener3.getActivationSpecConfig().getMaxConcurrency());
	assertEquals("Wrong custom concurrency on listener4", 7,
			listener4.getActivationSpecConfig().getMaxConcurrency());
}