Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 1.92 KB

guide-jms.asciidoc

File metadata and controls

53 lines (41 loc) · 1.92 KB

Messaging

ATTENTION: You are on the develop branch. This has been renamed to master. The develop branch will not be maintained anymore. It is only left here to avoid broken links to existing content. Please update links to point to the master branch. For details look at issue #320.

Messaging in Java is done using the JMS standard from JEE.

Products

For messaging you need to choose a JMS provider such as:

Receiver

As a receiver of messages is receiving data from other systems it is located in the service-layer.

JMS Listener

A JmsListener is a class listening and consuming JMS messages. It should carry the suffix JmsListener and implement the MessageListener interface or have its listener method annotated with @JmsListener. This is illustrated by the following example:

@Named
@Transactional
public class BookingJmsListener /* implements MessageListener */ {

  @Inject
  private Bookingmanagement bookingmanagement;

  @Inject
  private MessageConverter messageConverter;

  @JmsListener(destination = "BOOKING_QUEUE", containerFactory = "jmsListenerContainerFactory")
  public void onMessage(Message message) {
    try {
      BookingTo bookingTo = (BookingTo) this.messageConverter.fromMessage(message);
      this.bookingmanagement.importBooking(bookingTo);
    } catch (MessageConversionException | JMSException e) {
      throw new InvalidMessageException(message);
    }
  }
}

Sender

A sender of messages is writing to a data storage and hence is located in the dataaccess-layer.