Versions Compared

Key

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

...

Code Block
java
java
public class TheComponent implements ... {

      @Reference
   protected Service service;

   public void operation() {
      Message message = ...
      service.invoke(message);
   }

}

If the above implementation also needed to update a database using Hibernate in the same transaction as the message enque, it could be modified as follows to use the @ManagedTransaction annotation:

title
Code Block
java
java
@ManagedTransaction
public class TheComponent implements ... {

   @PersisitenceContext(unitName = "employee")
   Session session;

   @Reference
   protected Service service;

   public void operation() {
      Message message = ...
      long id = message.getId();

      Entity entity = session.find(Entity.class, id);
      entity.update(message.getUpdate());
      service.invoke(message);
   }
}

Info

Transacted Messaging and Request-Response
In a word: don't try it. Transacted messaging will not work with request reply. To see why, consider the following:

Code Block
java
java

@ManagedTransaction
public class TheComponent implements ... {

   @Reference
   protected Service service;

   public void operation() {
      Message message = ...
      Response response = service.invoke(message);
   }
}

The forward transaction will not commit until after the response is received and the operation() method has returned. However, the outgoing message will not be enqueued until the transaction commits. This means that the message can not be sent and consequently a response will never be received. The result will be a message timeout.

Receiving Responses with Transacted Messaging 

If you need to receive a response and require transacted messaging, use a callback. The following shows how this is configured: 

Code Block
xml
xml
<component name="AsyncClientServiceTheComponent">
   <implementation.java class="..."/>
   <reference name="service">
      <binding.jms requires="transactedOneWay">
         <destination jndiName="TheQueue"/>
      </binding.jms>
            <callback>
 
              <binding.jms requires="transactedOneWay">
      
             <destination jndiName="asyncClientServiceCallbackQueueTheCallbackQueue"/>
                </binding.jms>
            </callback>
        </reference>
    </component>

...

Service Auto Scaling

Fabric3 supports autoscaling where the number of message listeners for a service endpoint are dynamically resized based on workload. The following are the autoscaling attributes which can be configured per endpoint as attributes on binding.jms:

  • idle.limit
  • transaction.timout
  • receive.timeout
  • max.messages
  • recovery.interval
  • max.receivers
  • min.receivers