Java Reference
In-Depth Information
<bean id="backOffice"
class="com.apress.springenterpriserecipes.post.BackOfficeImpl">
<property name="destination" ref="mailDestination" />
<property name="jmsTemplate" ref="jmsTemplate" />
</bean>
</beans>
Pay special attention to the receiveTimout property of the JMS template. By default, this template
will wait for a JMS message at the destination forever, and the calling thread is blocked in the meantime.
To avoid waiting for a message so long, you should specify a receive timeout for this template. If there's
no message available at the destination in the duration, the JMS template's receive() method will return
a null message.
In your applications, the main use of receiving a message might be because you're expecting a
response to something or want to check for messages at an interval, handling the messages and then
spinning down until the next interval. If you intend to receive messages and respond to them as a
service, you're likely going to want to use the message-driven POJO functionality described later in this
chapter. There, we discuss a mechanism that will constantly sit and wait for messages, handling them by
calling back into your application as the messages arrive.
Sending and Receiving Messages to and from a Default Destination
Instead of specifying a message destination for each JMS template's send() and receive() method call,
you can specify a default destination for a JMS template. Then you will no longer need to inject it into
your message sender and receiver beans again.
<beans ...>
...
<bean id="jmsTemplate"
class="org.springframework.jms.core.JmsTemplate">
...
<property name="connectionFactory" ref="connectionFactory" />
<property name="defaultDestination" ref="mailDestination" />
</bean>
<bean id="frontDesk"
class="com.apress.springenterpriserecipes.post.FrontDeskImpl">
<property name="jmsTemplate" ref="jmsTemplate" />
</bean>
</beans>
<beans ...>
...
<bean id="jmsTemplate"
class="org.springframework.jms.core.JmsTemplate">
...
<property name="connectionFactory" ref="connectionFactory" />
<property name="defaultDestination" ref="mailDestination" />
</bean>
Search WWH ::




Custom Search