liveBook · Manning

Chapter 7: Chapter 7. Creating Java applications with ActiveMQ

What you will learn in chapter 7 of ActiveMQ in Action

This introduction presents an embedded ActiveMQ broker as a way for Java applications to serve both local and remote messaging clients.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction presents an embedded ActiveMQ broker as a way for Java applications to serve both local and remote messaging clients.

Key terms: embedded broker, VM protocol, remote applications

7.1 Embedding ActiveMQ using Java

This section introduces Java-based approaches to embedding and configuring an ActiveMQ broker.

7.1.1 Embedding ActiveMQ using the BrokerService

This section demonstrates configuring and starting an embedded ActiveMQ broker in Java with BrokerService, including important initialization order and when this approach is useful.

Key terms: BrokerService, brokerName, dataDirectory, SimpleAuthenticationPlugin, setPlugins(), addConnector(), plug-ins, connectors, broker start, BrokerFactory

7.1.2 Embedding ActiveMQ using the BrokerFactory

This section explains how to create an embedded ActiveMQ broker with BrokerFactory using XML-based or URI-only configuration.

Key terms: BrokerFactory, BrokerService, BrokerFactory.createBroker(), XBeanBrokerFactory, xbean: URI scheme, broker: URI scheme, network connectors, transport connectors, persistence, JMX

7.2 Embedding ActiveMQ using Spring

This section introduces ActiveMQ’s compatibility with Spring and the considerations for choosing an embedding method.

Key terms: Spring XML configuration file, embed, ActiveMQ broker, application and system architecture, skill set, maintain the solution

7.2.1 Pure Spring XML

This section explains how to configure and start an embedded ActiveMQ broker using pure Spring XML.

Key terms: pure Spring configuration, BrokerService, Spring container, ActiveMQ Java API, SpringConfig, ClassPathXmlApplicationContext, main method

7.2.2 Using the BrokerFactoryBean

This section explains how Spring’s BrokerFactoryBean simplifies configuring and starting an ActiveMQ broker.

Key terms: Spring factory beans, BrokerFactoryBean, Spring container, config, start, ActiveMQ XML configuration file

7.2.3 Using Apache XBean with Spring

This section explains ActiveMQ’s use of XBean-backed Spring configuration and illustrates starting a broker from a Java application.

Key terms: activemq.xml, Spring, Apache XBean, custom XML schema, XBeanBroker, activemq.base, Spring application context, publisher

7.2.4 Using a custom XML namespace with Spring

This section explains how a Spring configuration uses ActiveMQ’s custom XML namespace to define broker-related beans.

Key terms: XML namespace, amq, URI, schemaLocation, XSD, <amq:broker>, custom XML schema, Spring configuration file, broker-related beans, simple authentication plug-in

7.3 Implementing request/reply with JMS

This section explains the JMS request/reply pattern, how replies are routed and matched to requests, and how workers can be scaled.

Key terms: request/reply, broker, producer, consumer, asynchronous, JMSReplyTo, JMSCorrelationID, reply destination, correlation ID, temporary JMS destination

7.3.1 Implementing the server and the worker

This section implements and starts an embedded broker and a worker that responds to JMS requests.

Key terms: start(), BrokerService, embedded broker, setupConsumer(), message listener, JMSReplyTo, correlation ID, reply-to queue

7.3.2 Implementing the client

This section implements a request/reply client that initializes JMS resources, sends requests, and listens for replies on a temporary queue.

Key terms: start(), connection, session, destination, producer, request(), request queue, temporary queue, JMSReplyTo, correlation ID

7.3.3 Running the request/reply example

This section runs the request/reply example, relates it to large-scale asynchronous messaging, and describes Spring’s benefit for JMS configuration.

Key terms: Server, Client, requests, replies, worker, asynchronous messaging, brokers, workers, redundancy, failover

7.4 Writing JMS clients using Spring

This introduction describes how ActiveMQ and Spring support common JMS client configuration tasks.

Key terms: connection factory, JMS destinations, beans, message listener container, message listeners, helper bean classes, producers

7.4.1 Configuring JMS connections

This section explains how to configure an ActiveMQ connection factory and optionally pool JMS connections and sessions using Spring.

Key terms: ActiveMQConnectionFactory, ActiveMQConnection, Spring XML, PooledConnectionFactory, connectionFactory, JMS connections, sessions, Apache Commons Pool, classpath, Maven

7.4.2 Configuring JMS destinations

This section explains how to predefine JMS destinations and why predefined topics can be useful when clients must authenticate.

Key terms: JMS destinations, activemq.xml, ActiveMQTopic, ActiveMQQueue, constructor injection, client authentication

7.4.3 Creating JMS consumers

This section explains how Spring message listener containers receive JMS messages and configure the portfolio example’s consumers.

Key terms: message listener container, MLC, message listener, broker, DefaultMessageListenerContainer, DMLC, connection factory, destination, connection pooling

7.4.4 Creating JMS producers

This section shows how to send JMS messages with Spring’s JmsTemplate and MessageCreator and configure the publisher’s dependencies.

Key terms: JmsTemplate, MessageCreator, createMessage(), send(), JMS map message, publisher, JMS destinations, connection factory, pooled connection factory, JmsTemplate.send()

7.4.5 Putting it all together

The section brings the Spring JMS stock portfolio example together, describes its startup and output, and notes how Spring simplifies the original application.

Key terms: ActiveMQ broker, Spring application context, JMS clients, standard output, stock portfolio example, Spring utilities, Spring JMS

7.5 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 6: Chapter 6. Securing ActiveMQ Chapter 8: Chapter 8. Integrating ActiveMQ with application servers →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.