Java Code Examples for org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter#setDestinationResolver()

The following examples show how to use org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter#setDestinationResolver() . These examples are extracted from open source projects. 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
private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener, boolean pubSubDomain) throws JMSException {
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);

	given(destinationResolver.resolveDestinationName(session, "replyDestination", pubSubDomain))
			.willReturn(replyDestination);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDestinationResolver(destinationResolver);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);

	verify(destinationResolver).resolveDestinationName(session, "replyDestination", pubSubDomain);
	verify(reply).setJMSCorrelationID(correlationId);
	verify(queueSender).send(reply);
	verify(queueSender).close();
}
 
Example 2
@Override
protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) {
	Assert.state(this.messageHandlerMethodFactory != null,
			"Could not create message listener - MessageHandlerMethodFactory not set");
	MessagingMessageListenerAdapter messageListener = createMessageListenerInstance();
	Object bean = getBean();
	Method method = getMethod();
	Assert.state(bean != null && method != null, "No bean+method set on endpoint");
	InvocableHandlerMethod invocableHandlerMethod =
			this.messageHandlerMethodFactory.createInvocableHandlerMethod(bean, method);
	messageListener.setHandlerMethod(invocableHandlerMethod);
	String responseDestination = getDefaultResponseDestination();
	if (StringUtils.hasText(responseDestination)) {
		if (container.isReplyPubSubDomain()) {
			messageListener.setDefaultResponseTopicName(responseDestination);
		}
		else {
			messageListener.setDefaultResponseQueueName(responseDestination);
		}
	}
	QosSettings responseQosSettings = container.getReplyQosSettings();
	if (responseQosSettings != null) {
		messageListener.setResponseQosSettings(responseQosSettings);
	}
	MessageConverter messageConverter = container.getMessageConverter();
	if (messageConverter != null) {
		messageListener.setMessageConverter(messageConverter);
	}
	DestinationResolver destinationResolver = container.getDestinationResolver();
	if (destinationResolver != null) {
		messageListener.setDestinationResolver(destinationResolver);
	}
	return messageListener;
}
 
Example 3
private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener,
		String replyDestinationName, boolean pubSubDomain,
		QosSettings replyQosSettings) throws JMSException {
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);

	given(destinationResolver.resolveDestinationName(session, replyDestinationName, pubSubDomain))
			.willReturn(replyDestination);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDestinationResolver(destinationResolver);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);

	verify(destinationResolver).resolveDestinationName(session, replyDestinationName, pubSubDomain);
	verify(reply).setJMSCorrelationID(correlationId);
	if (replyQosSettings != null) {
		verify(queueSender).send(reply, replyQosSettings.getDeliveryMode(),
				replyQosSettings.getPriority(), replyQosSettings.getTimeToLive());
	}
	else {
		verify(queueSender).send(reply);
	}
	verify(queueSender).close();
}
 
Example 4
@Override
protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) {
	Assert.state(this.messageHandlerMethodFactory != null,
			"Could not create message listener - MessageHandlerMethodFactory not set");
	MessagingMessageListenerAdapter messageListener = createMessageListenerInstance();
	InvocableHandlerMethod invocableHandlerMethod =
			this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod());
	messageListener.setHandlerMethod(invocableHandlerMethod);
	String responseDestination = getDefaultResponseDestination();
	if (StringUtils.hasText(responseDestination)) {
		if (container.isReplyPubSubDomain()) {
			messageListener.setDefaultResponseTopicName(responseDestination);
		}
		else {
			messageListener.setDefaultResponseQueueName(responseDestination);
		}
	}
	QosSettings responseQosSettings = container.getReplyQosSettings();
	if (responseQosSettings != null) {
		messageListener.setResponseQosSettings(responseQosSettings);
	}
	MessageConverter messageConverter = container.getMessageConverter();
	if (messageConverter != null) {
		messageListener.setMessageConverter(messageConverter);
	}
	DestinationResolver destinationResolver = container.getDestinationResolver();
	if (destinationResolver != null) {
		messageListener.setDestinationResolver(destinationResolver);
	}
	return messageListener;
}
 
Example 5
private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener,
		String replyDestinationName, boolean pubSubDomain,
		QosSettings replyQosSettings) throws JMSException {
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);

	given(destinationResolver.resolveDestinationName(session, replyDestinationName, pubSubDomain))
			.willReturn(replyDestination);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDestinationResolver(destinationResolver);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);

	verify(destinationResolver).resolveDestinationName(session, replyDestinationName, pubSubDomain);
	verify(reply).setJMSCorrelationID(correlationId);
	if (replyQosSettings != null) {
		verify(queueSender).send(reply, replyQosSettings.getDeliveryMode(),
				replyQosSettings.getPriority(), replyQosSettings.getTimeToLive());
	}
	else {
		verify(queueSender).send(reply);
	}
	verify(queueSender).close();
}
 
Example 6
@Override
protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) {
	Assert.state(this.messageHandlerMethodFactory != null,
			"Could not create message listener - MessageHandlerMethodFactory not set");
	MessagingMessageListenerAdapter messageListener = createMessageListenerInstance();
	InvocableHandlerMethod invocableHandlerMethod =
			this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod());
	messageListener.setHandlerMethod(invocableHandlerMethod);
	String responseDestination = getDefaultResponseDestination();
	if (StringUtils.hasText(responseDestination)) {
		if (container.isReplyPubSubDomain()) {
			messageListener.setDefaultResponseTopicName(responseDestination);
		}
		else {
			messageListener.setDefaultResponseQueueName(responseDestination);
		}
	}
	MessageConverter messageConverter = container.getMessageConverter();
	if (messageConverter != null) {
		messageListener.setMessageConverter(messageConverter);
	}
	DestinationResolver destinationResolver = container.getDestinationResolver();
	if (destinationResolver != null) {
		messageListener.setDestinationResolver(destinationResolver);
	}
	return messageListener;
}