algorithms (22) Design Patterns (20) java (19) linux (14) Snippet (13) service mix (6) soa (4)

Adding a service Mix Bean

MVN Command used to create bean SU
mvn archetype:generate -DarchetypeGroupId=org.apache.servicemix.tooling
-DarchetypeArtifactId=servicemix-bean-service-unit -DarchetypeVersion=2010.01
-DgroupId=com.bytes.tutorial -DartifactId=bean-su -Dversion=1.01
1K downloaded  (servicemix-bean-service-unit-3.2.3.pom)
[INFO] Using property: groupId = com.bytes.tutorial
[INFO] Using property: artifactId = bean-su
[INFO] Using property: version = 1.01
[INFO] Using property: package = com.bytes.tutorial
Confirm properties configuration:
groupId: com.bytes.tutorial
artifactId: bean-su
version: 1.01
package: com.bytes.tutorial
Y: y
and the bean su is added to the parent folder, for it to be part of an assembly an entry has to be added into the assembly
like this under dependencies tag of sa’s pom.xml

A bean class MyBean is created automatically along with the entry in the xbean.xml
package com.bytes.tutorial;

import javax.annotation.Resource;
import javax.jbi.messaging.DeliveryChannel;
import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.InOnly;
import javax.jbi.messaging.InOut;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessageExchangeFactory;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
import javax.xml.namespace.QName;

import org.apache.servicemix.MessageExchangeListener;
import org.apache.servicemix.jbi.messaging.NormalizedMessageImpl;
import org.apache.servicemix.jbi.util.MessageUtil;

public class MyBean implements MessageExchangeListener {

private DeliveryChannel channel;

public void onMessageExchange(MessageExchange exchange)
throws MessagingException {

if (exchange.getStatus() == ExchangeStatus.ACTIVE)
System.out.println("Received exchange: " + exchange);
System.out.println("getPattern exchange: " + exchange.getPattern());
System.out.println("getStatus exchange: " + exchange.getStatus());
System.out.println("Role exchange: " + exchange.getRole().toString());
NormalizedMessage in = exchange.getMessage("in");
exchange.setMessage(in, "out");

the above bean just consumes a message exchange and prints the message and sends it back to the channel.
<bean:endpoint service="bytes:myBeanService" endpoint="endpoint" bean="#myBean"/>

<bean id="myBean" class="com.bytes.tutorial.MyBean"/>
Configure the bean as the above service so that it can be called from the EIP Pipeline.

we will see in the next post how to integrate the file poller the sender and this bean which will process the data in between.

No comments:

Post a Comment

Search 24 Bytes