Related docs:

Note that the following points also apply to standard components, but the examples / code is for lightweight components.

Correctly handling JBI exchange patterns

When your component receives an exchange with an ACTIVE status, you have to send the exchange back (either ACTIVE with a response / fault, or DONE / ERROR status).

If you component is only a consumer but uses asynchronous send, you will receive DONE / ERROR status. Be sure to receive them (by implementing the MessageExchangeListener interface) or polling them from the DeliveryChannel so that your component queue is not filled (this would block the provider component).

Handling streams

Take care of streams inside the content of the NormalizedMessage or attachments.
A stream may not be read twice, so if you need to do that, make sure to copy the stream to a re-readable source before processing.
In addition, you have to process the stream before sending back the DONE / ERROR status, because the consumer may close the stream when the status is received.

Synchronous / asynchronous

Sending JBI exchanges synchronously is much more easier to program.
However there are some drawbacks:

  • the current thread may be waiting for the answer doing nothing
  • synchronous send can not be used with the JCA flow

Clustering

If you want your component to be clustered (the same endpoint is activated on several ServiceMix containers with a clusterd flow), you need to take care of any state maintained by your component. ServiceMix assumes that your component is statefull and/or uses synchronous send, and thus, if your component send an exchange, the response or status will be returned back to the exact same component (on the same container instance). The main drawback is the node fails, the JBI exchange is lost until the node is restarted.

If your component does not maintain any state, of if the state is distributed across the whole cluster (for example you use a single database for all nodes), you can set the JbiConstants.STATELESS_PROVIDER or JbiConstants.STATELESS_CONSUMER property to Boolean.TRUE on the exchange. The clustered flows will ensure that the responses / status will be load-balanced across all nodes. Note that it only works if you use asynchronous send.

See also: NMR Flows

Transactional

TODO

Component types

Consumer component

You should inherit the ComponentSupport class and implements the MessageExchangeListener (if you use async send).

Provider component

You can extend the TransformerComponentSupport class.

Consumer / provider component

TODO: