Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 19. Implementing Destination Resolving Logic
Abstract
You can provide logic that allows your JMS endpoints to resolve destinations at run time. This is done by providing an implementation of the
DestinationChooser interface or the DestinationResolver interface.
Important
The Java Business Integration components of Red Hat JBoss Fuse are considered deprecated. You should consider migrating any JBI applications to OSGi.
It may not always be appropriate to hard code destinations into applications. Instead, you may want to allow the endpoints to dynamically discover the JMS destinations. The Red Hat JBoss Fuse JMS binding component provides two mechanisms for endpoints to dynamically discover destinations:
- 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.
19.1. Using a Custom Destination Chooser 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
Overview 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
Provider endpoints use a destination chooser to determine the JMS destination on which to send requests and receive replies. They have a default destination chooser that queries the message exchange for a property that specifies the destination to use. Consumer endpoints use destination choosers to determine where to send reply messages. In both cases, the destination chooser is the first method employed by an endpoint when looking for a JMS destination. If the destination chooser returns a destination, or a destination name, the endpoint will use the returned value.
To customize the logic used in choosing a destination, you can provide an implementation of the
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 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
Destination choosers implement the
org.apache.servicemix.jms.endpoints.DestinationChooser interface. This interface has a single method: chooseDestination().
chooseDestination(), whose signature is shown in Example 19.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.
Note
If the destination chooser returns a string, the endpoint will use a destination resolver to convert the string into a JMS destination. See Section 19.2, “Using a Custom Destination Resolver”.
Example 19.1. Destination Chooser Method
Object chooseDestination(MessageExchange exchange,
Object message);
The
message parameter can be either of the following type of object:
javax.jbi.messaging.NormalizedMessagejavax.jbi.messaging.FaultException
Example 19.2, “Simple Destination Chooser” shows a simple destination chooser implementation. It checks the message for a property that represents the JMS destination on which the request is to be placed.
Example 19.2. Simple Destination Chooser
Configuring an endpoint to use a destination chooser 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
You can configure an endpoint to use a custom destination chooser in one of two ways. The recommended way is to configure the destination chooser as a bean and have the endpoint reference the destination chooser's bean. The other way is to explicitly include the destination chooser's configuration as a child of the endpoint.
As shown in Example 19.3, “Configuring a Destination Chooser with a Bean Reference”, configuring an endpoint's destination chooser using a bean reference is a two step process:
- Configure a
beanelement for your destination chooser. - Add a
destinationChooserattribute that references the destination chooser's bean to your endpoint.
Example 19.3. Configuring a Destination Chooser with a Bean Reference
Example 19.4, “Explicitly Configuring a Destination Chooser” shows an example configuration using the
jms:destinationChooser element. This method is less flexible than the recommended method because other endpoints cannot reuse the destination chooser's configuration.
Example 19.4. Explicitly Configuring a Destination Chooser