Overview

Chapter 4. Connecting to ActiveMQ

ActiveMQ uses connectors and URI-based addressing to make broker connectivity straightforward and flexible. The chapter begins by explaining that a URI identifies not only the broker location, but also the protocol and optional settings used to communicate with it. Simple hierarchical URIs such as tcp://localhost:61616 are shown first, along with composite URIs used by higher-level protocols such as failover and static networking. A key point throughout is that the same URI structure is used on both the broker and client sides, and that query parameters can fine-tune behavior, although they must be written carefully because whitespace is not allowed.

The chapter then explores transport connectors, which handle client-to-broker communication over the network. It demonstrates how to configure multiple connectors in ActiveMQ’s XML configuration and how to adapt the stock portfolio example so it can connect through different transports. TCP is presented as the default, efficient, and reliable choice, while NIO is recommended when scalability or heavier traffic becomes important. UDP is covered as a faster but less reliable option that may help in firewall-constrained or time-sensitive environments, SSL is introduced for encrypted communication with the need for keystores and truststores, and HTTP/HTTPS is shown as a workaround for restrictive firewalls, though at a performance cost. The VM transport is also introduced as a non-network option for embedded brokers running inside the same JVM, offering better performance and simpler deployment.

Finally, the chapter broadens the view from single-broker connectivity to broker networks and resiliency. Static network connectors are used when broker addresses are known in advance, while failover provides automatic reconnection for clients if a broker becomes unavailable, improving robustness without changing application code. Dynamic discovery is then introduced through multicast and discovery transports, allowing brokers and clients to find each other automatically when addresses are not fixed. The peer connector simplifies networking of embedded brokers, and fanout allows a producer to send messages to multiple brokers at once. Overall, the chapter emphasizes that ActiveMQ’s connectivity model supports everything from simple local messaging to secure, scalable, and highly available distributed broker topologies.

Anatomy of a URI
A composite URI
Listing 4.1. Modifying stock portfolio publisher to support various connector URIs
Listing 4.2. Modifying stock portfolio consumer to support various connector URIs
Listing 4.3. Configuring the NIO transport connector
Producer sends messages using nio transport, consumer receives them using tcp transport
Application exchanges messages with embedded broker using vm transport
An example of a complex network of brokers topology
Two applications exchange messages using two brokers in a static network.
Two applications communicating using embedded brokers over peer protocol
Producer sends messages to multiple brokers using the fanout protocol

FAQ

What is a connector URI in ActiveMQ?A connector URI is a URI used to address an ActiveMQ broker and describe how to connect to it. It typically includes a scheme, a host and port, and optional query parameters for extra configuration.
What is the difference between transport connectors and network connectors?Transport connectors are used for client-to-broker communication, while network connectors are used for broker-to-broker communication to form broker networks or clusters.
Why are URIs important in ActiveMQ?URIs provide a simple, flexible way to identify brokers and configure connections. ActiveMQ uses them to specify protocols, broker locations, and optional connector settings.
What does a typical TCP connector URI look like?A typical TCP connector URI looks like tcp://hostname:port?key=value. For example, tcp://localhost:61616 connects to a broker on localhost port 61616.
When should you use the NIO transport connector?Use NIO when you need better scalability or have many clients and heavy traffic. It uses the NIO API underneath and can reduce resource usage on the broker side.
What are the main drawbacks of using UDP in ActiveMQ?UDP is faster in some cases but less reliable than TCP. It can lose packets, deliver them out of order, and even lose control commands, which may affect the JMS connection.
How does the SSL transport connector secure communication?SSL adds encryption over TCP to provide secure communication between clients and brokers. It uses keystores, truststores, certificates, and JSSE system properties to configure secure connections.
Why would you use the VM transport connector?The VM transport is used for embedded brokers inside the same JVM. It avoids network overhead, improves performance, and allows clients to communicate directly with the broker in memory.
What is the failover protocol used for?Failover provides automatic reconnection if a broker becomes unavailable. It can try multiple broker URIs and reconnect automatically without requiring application changes.
What is the purpose of the multicast, discovery, peer, and fanout connectors?Multicast and discovery help brokers and clients find each other dynamically. Peer makes it easy to network embedded brokers, and fanout lets a producer send messages to multiple brokers at once.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • ActiveMQ in Action ActiveMQ in Action ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • ActiveMQ in Action ActiveMQ in Action ebook for free