Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
@Component
public class Client ... {

     @JMS(value = @JMSConfiguration(destination = "ServiceQueue"))
    protected Service service;

    public String messageprocess(String message) {
		// ...
        service.onReceive(message);
		// ...
    }
}
 
@Component
@JMS(value = @JMSConfiguration(destination = "ServiceQueue"))
public class ServiceImpl implements Service {

    public Stringvoid onReceive(String message) {
       // ...
    }
}
 
public interface Service {
	@OneWay
	Stringvoid onReceive(String message);
}

...

Configuring request-response operations involves specifying a separate response queue in addition to the forward queue:

Code Block
xml
languagexmljava
<component name="RequestResponseClient">
   <implementation.java class="..."/>@Component
public class Client ... {

   <reference name="service">
@JMS(value = @JMSConfiguration(destination = "ServiceQueue", responseDestination="ResponseQueue"))
    protected <binding.jms>Service service;

    public void process() <destination name="serviceQueue"/>
{
		// ...
        <response>String response = service.onReceive(message);
		// ...
    }
}
 
@Component
@JMS(value = @JMSConfiguration(destination = <destination jndiName"ServiceQueue", responseDestination="responseQueueResponseQueue"/>))
public class ServiceImpl implements Service {

  </response>  public String onReceive(String message) {
</binding.jms>    </reference> </component>  <component name="RequestResponseService">
   <implementation.java class="..."/>
// ...
	   <service>return response;
    }
<binding.jms>}
 
public interface Service {
	
	String onReceive(String  <destination name="serviceQueuemessage);
}
Code Block
xml
xml
<component name="Client">
   <implementation.java class="..."/>
     <reference name="service">
   <response>   <binding.jms>
         <destination jndiNamename="responseQueueServiceQueue"/>
         </response><response>
      </binding.jms>    </service> </component>

Using Callbacks

...

 <destination jndiName="ResponseQueue"/>
         </response>
      </binding.jms>
   </reference>
</component>

<component name="Service">
   <implementation.java class="..."/>
   <service>
      <binding.jms>
         <destination name="ServiceQueue"/>
         <response>
            <destination jndiName="ResponseQueue"/>
         </response>
      </binding.jms>
   </service>
</component>

Using Callbacks

While JMS is an asynchronous model, it is important to note that the client component will block on request-response operations until a response is received. In some cases, this is the desired behavior. In other situations, such as long-running interactions, looser coupling is required where the client can continue processing without waiting for a response to be returned. Callbacks can be used to provide responses at some later point in time. Configuring callbacks involves specifying a callback queue:

 

Code Block
languagejava
@Component
public class CallbackClientImpl implements Client, ConsumerCallback {


    @JMS(value = @JMSConfiguration(destination = "ServiceQueue"), callback = @JMSConfiguration(destination = "CallbackQueue"))
    protected Service service;


    public void invoke(String message) {
        service.onReceive(message);
    }

    public void onResponse(String message) {
		// ...
    }
}


public interface ConsumerCallback {
    @OneWay
    void onResponse(String message);
}


@Component
@JMS(value = @JMSConfiguration(destination = "ServiceQueue"), callback = @JMSConfiguration(destination = "CallbackQueue"))
public class ServiceImpl implements Service {


    @Callback
    protected ConsumerCallback callback;

    public void onReceive(String message) {
        callback.onResponse(message);
    }
}
 
public interface Service {
	@OneWay
	void onReceive(String message);
}

And in XML:

Code Block
xml
xml
<component name="CallbackClient">
   <implementation.java class="..."/>
   <reference name="service">
      <binding.jms>
         <destination name="serviceQueueServiceQueue"/>
      </binding.jms>
      <callback>
         <binding.jms>
            <destination name="callbackQueueCallbackQueue"/>
         </binding.jms>
      </callback>
   </reference>
</component>

<component name="CallbackService">
   <implementation.java class="..."/>
   <service>
      <binding.jms>
         <destination name="serviceQueueServiceQueue"/>
      </binding.jms>
      <callback>
         <binding.jms>
            <destination name="callbackQueueCallbackQueue"/>
         </binding.jms>
      </callback>
   </service>
</component>

...