Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 7. Implementing Destination Resolving Logic
Abstract
DestinationChooser interface or the DestinationResolver interface.
- destination choosers
- Destination choosers are specific to the Red Hat JBoss Fuse JMS binding component. They are the first mechanism used by an endpoint when it trys to pick a JMS destination.Destination choosers implement the
org.apache.servicemix.jms.endpoints.DestinationChooserinterface. - destination resolvers
- Destination resolvers are part of the Spring JMS framework. They are used when the JMS destination is specified using a string. This can happen if either the destination chooser returns a string or if the endpoint's destination is configured using the
destinationNameattribute.Destination resolvers implement theorg.springframework.jms.support.destination.DestinationResolverinterface.
7.1. Using a Custom Destination Chooser Copier lienLien copié sur presse-papiers!
Overview Copier lienLien copié sur presse-papiers!
org.apache.servicemix.jms.endpoints.DestinationChooser interface and configure the endpoint to load it. The configured destination chooser will be used in place of the default destination chooser.
Implementing a destination chooser Copier lienLien copié sur presse-papiers!
org.apache.servicemix.jms.endpoints.DestinationChooser interface. This interface has a single method: chooseDestination().
chooseDestination(), whose signature is shown in Example 7.1, “Destination Chooser Method”, takes the JBI message exchange and a copy of the message. It returns either a JMS Destination object or a string representing the destination name.
Example 7.1. Destination Chooser Method
Object chooseDestination(MessageExchange exchange,
Object message);message parameter can be either of the following type of object:
javax.jbi.messaging.NormalizedMessagejavax.jbi.messaging.FaultException
Example 7.2. Simple Destination Chooser
package com.widgetVendor.example;
import package org.apache.servicemix.jms.endpoints.DestinationChooser;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.NormalizedMessage;
import javax.jms.Destination;
public class widgetDestinationChooser implements DestinationChooser {
public static final String DESTINATION_KEY = "org.apache.servicemix.jms.destination";
public SimpleDestinationChooser() {
}
public Object chooseDestination(MessageExchange exchange, Object message) {
Object property = null;
if (message instanceof NormalizedMessage) {
property = ((NormalizedMessage) message).getProperty(DESTINATION_KEY);
}
if (property instanceof Destination) {
return (Destination) property;
}
if (property instanceof String) {
return (String) property;
}
return new String("widgetDest");
}
}
Configuring an endpoint to use a destination chooser Copier lienLien copié sur presse-papiers!
- Configure a
beanelement for your destination chooser. - Add a
destinationChooserattribute that references the destination chooser's bean to your endpoint.
Example 7.3. Configuring a Destination Chooser with a Bean Reference
<beans xmlns:jms="http://servicemix.apache.org/jms/1.0"
... >
...
<jms:provider service="my:widgetService"
endpoint="jbiWidget"
destinationName="widgetQueue"
connectionFactory="#connectionFactory"
destinationChooser="#widgetDestinationChooser" />
<bean id="widgetDestinationChooser"
class="com.widgetVendor.example.widgetDestinationChooser" />
...
</beans>
jms:destinationChooser element. This method is less flexible than the recommended method because other endpoints cannot reuse the destination chooser's configuration.
Example 7.4. Explicitly Configuring a Destination Chooser
<beans xmlns:jms="http://servicemix.apache.org/jms/1.0"
... >
...
<jms:provider service="my:widgetService"
endpoint="jbiWidget"
destinationName="widgetQueue"
connectionFactory="#connectionFactory">
<jms:destinationChooser>
<bean id="widgetDestinationChooser"
class="com.widgetVendor.example.widgetDestinationChooser" />
</jms:destinationChooser>
</jms:provider>
...
</beans>