Java Reference
In-Depth Information
} catch (JMSException e) {
throw new RuntimeException(e);
} finally {
if (conn != null) {
try {
conn.close();
} catch (JMSException e) {
}
}
}
}
}
Most of the code in this method is similar to that for sending JMS messages, except that you create
a message consumer and receive a JMS message from it. Note that here we used the conn's start()
method here, although we didn't in the FrontDeskImpl example before. When using a Connection to
receive messages, you can add listeners to the connection that are invoked on receipt of a message, or
you can block synchronously, waiting for a message to arrive. The container has no way of knowing
which approach you will take and so it doesn't start polling for messages until you've explicitly called
start() . If you add listeners or do any kind of configuration, you do so before you invoke start() .
Finally, you create two bean configuration files—one for the front desk subsystem (e.g.,
beans-front.xml ), and one for the back office subsystem (e.g., beans-back.xml )—in the root of
the classpath.
<beans xmlns=" http://www.springframework.org/schema/beans"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd ">
<bean id="frontDesk"
class="com.apress.springenterpriserecipes.post.FrontDeskImpl" />
</beans>
<beans xmlns=" http://www.springframework.org/schema/beans"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd ">
<bean id="backOffice"
class="com.apress.springenterpriserecipes.post.BackOfficeImpl" />
</beans>
Now your front desk and back office subsystems are ready to send and receive JMS messages. You
must start up your message broker before sending and receiving messages with the following main
classes. To run them, first run FrontDeskMain ; then run BackOfficeMain in another window or console.
Search WWH ::




Custom Search