MOM (Message-Oriented Middleware)

A class of software used for asynchronous, loosely coupled, reliable, scalable, secure communication in distributed applications or systems. The overall idea of a MOM is that it acts as a message mediator between a message sender and a message receiver. This mediation provides a whole new level of loose coupling.

JMS (Java Messaging Service)

Java platform technical specifications for MOMS. An abstraction similar to JDBC and relational database communication.

Message generation > send > receive > process

  • Provider: JMS interface implementation written in pure Java (such as ActiveMQ)
  • Domains: message passing methods, including P2P and Pub/Sub
  • Connection Factory: The client uses the Connection factory to create a Connection to the JMS Provider
  • Destination: The object to which the message is addressed, sent, and received

Message domain

P2P (peer-to-peer) queues are used as destinations. Messages can be sent and received synchronously or asynchronously, and each message is sent to a Consumer only once.

Consumer can use a MessageConsumer. The receive () synchronously receive messages, but can be by using MessageConsumer. SetMessageListener () to register a MessageListener realize asynchronous receive.

Multiple consumers can be registered to the same queue, but a message can only be received by one Consumer, who then confirms the message. And in this case, the Provider polls all registered consumers

Pub/Sub (publish/subscribe) uses topics as destinations, publishers send messages to topics, and subscribers register to receive messages from topics. Any message sent to topic is automatically delivered to all subscribers. The receiving mode (synchronous or asynchronous) is the same as that of the P2P domain. Topic does not hold messages for subscribers unless explicitly specified. Of course, this can be achieved through Durable subscriptions. In this case, the Provider stores messages for the subscriber when it disconnects from the Provider. When the persistent subscriber reconnects, it receives all messages that were not consumed during the disconnection period

steps

  1. Get the connection factory
  2. Create connections using connection factories
  3. Start the connection
  4. Create a session from the connection
  5. Access to the Destination
  6. Create Producer and message
  7. To create a Consumer
    1. Send or receive a message
    2. Register message listeners (optional)
  8. Shutting down resources (Connection, Session, Producer, Consumer, etc.)