Entering content frame

Procedure documentation Simple Point-to-Point Scenario Locate the document in its SAP Library structure

Use

The production units report their material requirements to the central warehouse management by means of the JMS. Since multiple message generators report their requirements to one central instance, it makes sense to use a point-to-point connection. In this case, all production units send their requirements to the same queue. The central warehouse management retrieves the requirements from this queue and triggers the deliveries to the production unit.

The requirement notification consists of five fields:

·        ID of the requirement notification

·        ID of the production unit

·        ID of the material

·        Amount

·        Requirement date

 

This graphic is explained in the accompanying text

For this scenario you require a message sender for the production units and a message receiver for the warehouse management.

For each program run, the message sender sends exactly one requirement notification to the queue. The parameters for the message are transmitted to the program in the command line.

The sender object is generated as part of the known procedure by using the naming context, the queue connection factory, the queue, the queue connection, and the queue session. The session is generated without a transaction and with an automatic confirmation of the messages when they are sent (AUTO_ACKNOWLEDGE).

This graphic is explained in the accompanying text

queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

queueSender = queueSession.createSender(queue);

A message of the type MapMessage is then generated from the input parameters and sent. The parameter keys that are used are collected in a pool of constants to ensure consistent usage by the components involved.

This graphic is explained in the accompanying text

message = queueSession.createMapMessage();

message.setString(Constants.REQ_ID_KEY, args[0]);

message.setString(Constants.PU_ID_KEY, args[1]);

message.setString(Constants.MAT_ID_KEY, args[2]);

message.setString(Constants.MAT_AMOUNT_KEY, args[3]);

message.setString(Constants.MAT_REQ_DATE_KEY, args[4]);

queueSender.send(message);

The warehouse management receives messages synchronously in an endless loop and returns a relevant message for each message received.

The receiver object is generated as part of the known procedure by using the naming context, the queue connection factory, the queue, the queue connection, and the queue session. The session is generated without a transaction and with an automatic confirmation of the messages when they are received (AUTO_ACKNOWLEDGE).

This graphic is explained in the accompanying text

queueSession = queueConnection.createQueueSession(false,

                    Session.AUTO_ACKNOWLEDGE);

queueReceiver = queueSession.createReceiver(queue);

Before the connection is started, a separate thread is started for interaction with the user.

This graphic is explained in the accompanying text

Thread stop = new Thread(new Commandline(this));

stop.start();

System.out.println("Now receiving, enter q and" +

                    "<Return> to end the program");

Then the queue is checked for messages synchronously in an endless loop. When a message is received, its type is checked, and the fields of the message are output. You can terminate the receiving process by entering q.

This graphic is explained in the accompanying text

queueConnection.start();

while (!(key == 'q')) {

   Message m = queueReceiver.receive(1);

   if (m != null) {

      if (m instanceof MapMessage) {

         message = (MapMessage) m;

         System.out.println("Reading message with content: ");

         for (Enumeration e = message.getMapNames() ;

            e.hasMoreElements() ;) {

            String key = (String)e.nextElement();

            System.out.println(key+": "+message.getString(key));

         }

      }

   }

}

Procedure

...

       1.      Generation and registration of the Queue

Using the Visual Administrator tool of the SAP J2EE Engine, generate a queue named ProductionUnitRequirements.

       2.      Starting the receiver

Make sure that the SAP J2EE Engine is running. In the directory of the compiled example packages, open a window for the command line, and start the receiver for the warehouse management with the following command:

java -cp .;<Path to J2EE Client Library>;<Path to JMS API Library> scenario1.WarehouseReceiver

       3.      Starting the sender

In the directory of the compiled example packages, open a window for the command line, and start the sender for the production unit with the following command:

java -cp .;<Path to J2EE Client Library>;<Path to JMS API Library> scenario1.ProductionUnitSender REQ1 PU1 P-100 2 06.03.2003

Result

The sender then sends a message to its queue with the parameters that were specified when the program was started. The following message appears on the receiver end:

Reading message with content:

RequirementID: REQ1

ProductionUnitID: PU1

MaterialID: P-100

MaterialAmount: 2

MaterialRequirementDate: 06.03.2003

The sender can now be called as many times as necessary. You can also end the receiver program, send one or more messages, and start the receiver program again. Any messages that were sent in the meantime are then displayed correctly by the receiver. Since the sender and the receiver are separated by using the queue, no messages are lost.

 

See also:

 

Source Code of JMS Scenarios

 

 

Leaving content frame