...
The ServiceMix Bean component provides integration with beans (POJOs) with the JBI bus to make it easy to use POJOs to process JBI message exchanges. Like in an Message Driven Bean in J2EE a POJO will receive a message from the NMR and process it in any way it likes. Unlike in a JMS component where the coding is already done the Bean component gives the developer the freedom to create any type of message handling but it must be hand coded all the way.
Maven Archetype
You can simple create a bean SU (with a bean sample) using the servicemix-bean-service-unit archetype :
Code Block |
---|
mvn archetype:create \
-DarchetypeGroupId=org.apache.servicemix.tooling \
-DarchetypeArtifactId=servicemix-bean-service-unit \
-DarchetypeVersion=2010.01 \
-DgroupId=your.group.id \
-DartifactId=your.artifact.id \
-Dversion=your-version
|
Once you've customized the service unit, simply install the SU:
Code Block |
---|
mvn install
|
Info | ||
---|---|---|
Remember that to be deployable in ServiceMix, the ServiceUnit has to be embedded in a Service Assembly: only the Service Assembly zip file can be deployed in ServiceMix.
|
Endpoint Configuration
Code Block | ||||
---|---|---|---|---|
| ||||
<beans xmlns:bean="http://servicemix.apache.org/bean/1.0">
<bean:endpoint service="test:service" endpoint="endpoint" bean="#listenerBean"/>
<bean id="listenerBean" class="org.apache.servicemix.bean.beans.ListenerBean"/>
</beans>
|
Attention: The Bean Endpoint schema allows to set a Bean or a Bean Name. The Bean will create a single instance of the POJO per endpoint whereas the Bean Name will create an instance per request (message exchange).
POJOs
There are several kind of POJOs you can deploy to servicemix-bean
.
MessageExchangeListener
The first kind of POJOs you can deploy implement the MessageExchagneListener
interface. In such a case, servicemix-bean
acts as a replacement of the lightweight container component. This level offers the most control on the exchange received and sent. This is usually used with the injected DeliveryChannel
to send back the exchanges, or if the POJOs needs to act as a consumer (i.e. creating and sending exchanges to other services).
These POJOs are low-level POJOs: you need to understand the JBI Api and Message Exchange Patterns to correctly handle incoming exchanges.
Note that at this point (v 3.1), there is no base class that you can inherit to speed you in this process of implementing a POJO to handle JBI exchanges, but hopefully it will come in the future.
Section | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Section | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Section | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Disclaimer
In versions 3.1 to 3.1.2 the ServiceMix Bean component will not handle asynchronous messages correctly because the final send of the message marked as DONE back to the NMR will be handled as a consumer message and that fails because there is no corresponding provider message. The only workaround is to send the messages synchronously.
Note: This was resolved in 3.1.3, 3.2.x and later via SM-1110.
MessageExchange dispatching
If the POJO deployed implements the org.apache.servicemix.MessageExchangeListener
, every message received for this POJO will be dispatched to the onMessageExchange
method.
In other cases, exchanges in a provider role will be dispatched according to the MethodInvocationStrategy
configured on the endpoint. The default one try to find the method according to the operation name defined on the exchange. If there is only a single method acting as an operation, it will always be used.
Annotations
The servicemix-bean
component can accept different kind of POJOs. These POJOs may be annotated to customize their behavior. All the following annotations belong to the org.apache.servicemix.bean
package.
Annotation | Target | Description |
---|---|---|
Method |
| |
Parameter |
| |
Type |
| |
Type | This annotation is mandatory if the bean is automatically searched from a list of packages. | |
Field |
| |
Method |
| |
Parameter |
| |
Parameter |
|
In addition, standard annotations can be used:
Annotation | Target | Description |
---|---|---|
Field | The Resource annotation marks a resource that is needed by the application. Currently, this annotation is only supported on fields of type | |
Method | The PostConstruct annotation is used on a method that needs to be executed after dependency injection is done to perform any initialization. | |
Method | The PreDestroy annotation is used on methods as a callback notification to signal that the instance is in the process of being removed by the container. |
The following interfaces are part of this API:
Interface | Description |
---|---|
When the POJO implements this interface, all exchanges will be dispatched to the | |
This interface can be used to define a property on the bean, annotated with the |
Examples
URI
You can use a handy URI to refer to beans using the Spring names of beans.
...