Enterprise Integration Zone is brought to you in partnership with:

Michael has posted 16 posts at DZone. View Full User Profile

Habari MDC Container - Message Driven Components for Java and Delphi Integration

06.21.2010
| 2979 views |
  • submit to reddit
Location: 
Germany

betasoft is pleased to announce Habari MDC Container, a new application server framework for Delphi™ based on the JEE concept of Message Driven Beans. Designed for event-driven application, message driven components are business objects whose execution is triggered by messages instead of by method calls. With Habari MDC Container, Delphi developers can write lightweight application servers, which connect to open source JMS message brokers (Apache ActiveMQ, JBoss HornetQ or Sun OpenMQ are already supported) and process messages from topics and queues. Cross-language client applications can use services in the container for simple tasks like centralized logging, monitoring, and configuration but also implement advanced solutions like load balancing and legacy application integration.

Example code

This example creates an embedded Habari MDC Container, adds a JMS connection factory and a queue, and deploys a message driven component:

  // create the container
  Container := THabariContainer.Create;
  // bind a connection factory
  Container.BindFactory('DefaultConnectionFactory', TBTJMSConnectionFactory.Create);
  // bind a queue
  Container.BindQueue('jms/HelloWorldQueue', 'TOOL.DEFAULT');
  // deploy the HelloWorld MDC
  Container.Deploy(THelloWorldMDC);

 The interface declaration of the message driven component contains the two methods which need to be implemented, Configure and OnMessage: 

  THelloWorldMDC = class(TInterfacedObject, IMDCConfigProvider, IMessageListener)
public
procedure OnMessage(const AMessage: IMessage);
procedure Configure(var AMappedName: string; const AProperties: IActivationConfigProperties);
end;

 The implementation part shows that like in an message driven bean, a message driven component uses a mapped name for the JMS destination:

procedure THelloWorldMDC.Configure(var AMappedName: string;
const AProperties: IActivationConfigProperties);
begin
AMappedName := 'jms/HelloWorldQueue';
end;

procedure THelloWorldMDC.OnMessage(const AMessage: IMessage);
begin
WriteLn('Hello World - ' + (AMessage as ITextMessage).Text);
end;

Running the container with a Log4D console appender will show the deployment process, which includes a component verification, on the console. (If the JMS message broker is not running, the container will retry).

The container is now connected with the JMS broker and listens for messages on the queue TOOL.DEFAULT. Messages sent to this queue will be received and displayed by the HelloWorld MDC:

 

 Console output for Habari MDC Container

Deployed hello world component receiving JMS message

0
Published at DZone with permission of its author, Michael Justin.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)