7.4. Decode the Payload

Procedure 7.1. Task

  1. The process method is only the start. Now we must provide methods to decode the incoming Message payload (the Body):
    		  public void reserveSeat (Message message) throws Exception
    {
    	String seatNumber = message.getBody().get(“org.example.flight.seatnumber”);
    	String flight = 
            message.getBody().get(“org.example.flight.flightnumber”);
    	
    	boolean success = 
            airlineReservationSystem.reserveSeat(seatNumber, flight);
    	
    	// now create a response Message
    	Message responseMessage = ...
    	
    	responseMessage.getHeader().getCall().setTo(
            message.getHeader().getCall().getReplyTo()
        );
        
    	responseMessage.getHeader().getCall().setRelatesTo(
            message.getHeader().getCall().getMessageID()
        );
    	
    	// now deliver the response Message
    }
    This code illustrates how the information within the body is extracted and then used to invoke a method on some business logic. In the case of reserveSeat, a response is expected by the client. This response message is constructed using any information returned by the business logic as well as delivery information obtained from the original received message. In this example, we need the To address for the response, which we take from the ReplyTo field of the incoming message. We also need to relate the response with the original request and we accomplish this through the RelatesTo field of the response and the MessageID of the request.
  2. Code every operation supported by the service similarly.
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.