Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow value expressions for messaging listener annotation destinations [SPR-12134] #16750

Closed
spring-projects-issues opened this issue Aug 29, 2014 · 3 comments
Assignees
Labels
in: messaging type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Aug 29, 2014

zyro opened SPR-12134 and commented

using jms messaging as example here. but probably other messaging impls (websocket, amqp, etc.) show the same behavior.

currently, only "plain" String destinations are supported for the destination argument of @JmsListener. we faced a use case where it made sense to pull those values out of properties. i think this can be generalized to a request for support of injection/resolution of value expressions for destination arguments (e.g. just like it works with @Value).

the following example code shows our current workaround, which could likely be implemented in a better way but it shows the desired behavior:

@Configuration
@EnableJms
public class JmsConfiguration {

	@Autowired
	private CustomDynamicDestinationResolver destinationResolver;
	
	@Bean
	public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(final ConnectionFactory connectionFactory) {
		final DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
		factory.setConnectionFactory(connectionFactory);
		factory.setDestinationResolver(destinationResolver);
		return factory;
	}

}

@Component
public class ExampleReceiver {

	@JmsListener(containerFactory = "jmsListenerContainerFactory", destination = "${my.destination.value.expression.property.key}")
	public void handleMessage(String example) {
		System.out.println(example);
	}

}

@Component
public class CustomDynamicDestinationResolver extends DynamicDestinationResolver {

	@Autowired
	private AbstractBeanFactory beanFactory;
	
	@Override
	public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain) throws JMSException {
		String parsedDestinationName = beanFactory.resolveEmbeddedValue(destinationName);
		return super.resolveDestinationName(session, parsedDestinationName, pubSubDomain);
	}
	
}

thanks, zyro


Affects: 4.1 RC2

Issue Links:

  • AMQP-424 Allow value expressions for messaging listener annotation destinations

Referenced from: commits 8c4388d

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 1, 2014

Stéphane Nicoll commented

Thanks for report. Just a thought, the jmsListenerContainerFactory value in your @JmsListener is unecessary as it matches the name of the default value. Check the doc for more details.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 1, 2014

Stéphane Nicoll commented

This one is easy enough to make it before 4.1.GA. All attributes can now be resolved using property place holders. I'll apply the same logic for @RabbitListener wherever it makes sense.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 1, 2014

zyro commented

awesome! thank you.

@spring-projects-issues spring-projects-issues added in: messaging type: enhancement labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.1 GA milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: messaging type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants