Over a million developers have joined DZone.

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

DZone's Guide to

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

· ·
Free Resource

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

 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)
procedure OnMessage(const AMessage: IMessage);
procedure Configure(var AMappedName: string; const AProperties: IActivationConfigProperties);

 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);
AMappedName := 'jms/HelloWorldQueue';

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

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


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}