Hi Sanky,

If you need to create the POJO, you can use the servicemix-bean component. If you have existing POJO, you can expose it using the servicemix-cxf-se component.

For example, you can create a service that use a POJO method like this :

import org.apache.servicemix.jbi.listener.MessageExchangeListener;
import org.apache.servicemix.jbi.util.MessageUtil;
import org.apache.servicemix.jbi.jaxp.SourceTransformer;

import javax.annotation.Resource;
import javax.jbi.messaging.DeliveryChannel;
import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
import javax.xml.transform.Source;

public class ListenerBean implements MessageExchangeListener {

    @Resource
    private DeliveryChannel channel;

public void onMessageExchange(MessageExchange exchange) throws MessagingException {
        if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
NormalizedMessage message = exchange.getMessage("in");
                        Source content = message.getContent();
                        //process content according to your logic
                        //e.g. to access the message body as a String use
                        String body = (new 
SourceTransformer()).toString(content);
                        body = MyPOJO.transform(body);
                        message.setContent(new StringSource(body));
                        exchange.setMessage(message, "out");
                        channel.send(exchange);
        }
    }

}

This POJO is the listener one: it receives a message, extracts the content and send out (if the MEP InOut is used).

You can deploy it with the following xbean.xml:
<bean:endpoint service="MyService" endpoint="listener" bean="#myBean"/>
<bean id="myBean" class="com.my.package.Bean"/>

For the poller, you can use servicemix-quartz component to call a bean that trigger the message sending. You can define your own servicemix-quartz marshaler to define the message content. After you deploy it using a xbean.xml like this:

<quartz:endpoint service="MyService endpoint="provider" targetService="MyService" endpoint="listener">
  <quartz:jobDetail>
    <quartz:jobDetail>
      <quartz:jobDataAsMap>
        <quartz:property key="xml"><![CDATA[
          <hello>world</hello>
        ]]></quartz:property>
      </quartz:jobDataAsMap>
    </quartz:jobDetail>
  </quartz:jobDetail>
  <quartz:triggers>
    <quartz:simple repeatCount="0" repeatInterval="1000" />
    <quartz:cron cronExpression="0 * 1 * * ?" />
  </quartz:triggers>
  <quartz:marshaler>
    <bean class="org.apache.servicemix.quartz.CustomMarshaler" />
  </quartz:marshaler>
</quartz:endpoint>

Regards
JB


sanky wrote:
Hi,All...

I want to exchange message from one POJO(sender) to another(receiver).
I am looking for-
1. how to configure POJO's for this,  may be in the form of xbean.xml..
   Any example on this will be useful..
   I have also gone through the link--
http://servicemix.apache.org/pojo-support.html
   But dont understand everything. Please help..

2. Also help me to understand how sender will be triggered to send message
once sender and receiver service assemblies (SA) are deployed


Thanks,
Sanket

Reply via email to