Chapter 9. Consumer Endpoints
Abstract
Overview
Figure 9.1. Consumer Endpoint
Procedure
- Add a
consumer
element to yourxbean.xml
file. - Add a
wsdl
attribute to theconsumer
element. - If your WSDL defines more than one service, you will need to specify a value for the
service
attribute. - If the service you choose defines more than one endpoint, you will need to specify a value for the
endpoint
attribute. - Specify the details for the target of the requests received by the endpoint.
- If your endpoint is going to be receiving binary attachments set its
mtomEnabled
attribute totrue
. - If your endpoint does not need to process the JBI wrapper set its
useJbiWrapper
attribute tofalse
. - If you are using any of the advanced features, such as WS-Addressing or WS-Policy, specify a value for the
busCfg
attribute.
Specifying the WSDL
wsdl
attribute is the only required attribute to configure a consumer endpoint. It specifies the location of the WSDL document that defines the endpoint being exposed. The path used is relative to the top-level of the exploded service unit.
Example 9.1. Minimal Consumer Endpoint Configuration
<beans xmlns:cxfbc="http://servicemix.apache.org/cxfbc/1.0" ... > ... <cxfbc:consumer wsdl="/wsdl/widget.wsdl" /> ... </beans>
Specifying the endpoint details
service
element you will need to specify a value for the consumer's service
attribute. The value of the consumer's service
attribute is the QName of the WSDL service
element that defines the desired service in the WSDL document. For example, if you wanted your endpoint to use the WidgetSalesService in the WSDL shown in Example 9.2, “WSDL with Two Services” you would use the configuration shown in Example 9.3, “Consumer Endpoint with a Defined Service Name”.
Example 9.2. WSDL with Two Services
<definitions ... xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://demos.widgetVendor.com" ...> ... <service name="WidgetSalesService"> <port binding="WidgetSalesBinding" name="WidgetSalesPort"> <soap:address location="http://widget.sales.com/index.xml"> </port> </service> <service name="WidgetInventoryService"> <port binding="WidgetInventoryBinding" name="WidgetInventoryPort"> <soap:address location="http://widget.inventory.com/index.xml"> </port> </service> ... <definitions>
Example 9.3. Consumer Endpoint with a Defined Service Name
<beans xmlns:cxfbc="http://servicemix.apache.org/cxfbc/1.0"
xmlns:widgets="http://demos.widgetVendor.com"
... >
...
<cxfbc:consumer wsdl="/wsdl/widget.wsdl"
service="widgets:WidgetSalesService" />
...
</beans>
endpoint
attribute. The value of the endpoint
attribute corresponds to the value of the WSDL port
element's name
attribute. For example, if you wanted your endpoint to use the WidgetEasternSalesPort in the WSDL shown in Example 9.4, “Service with Two Endpoints” you would use the configuration shown in Example 9.5, “Consumer Endpoint with a Defined Endpoint Name”.
Example 9.4. Service with Two Endpoints
<definitions ... xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://demos.widgetVendor.com" ...> ... <service name="WidgetSalesService"> <port binding="WidgetSalesBinding" name="WidgetWesternSalesPort"> <soap:address location="http://widget.sales.com/index.xml"> </port> <port binding="WidgetSalesBinding" name="WidgetEasternSalesPort"> <jms:address jndiConnectionFactoryName="ConnectionFactory" jndiDestinationName="dynamicQueues/test.Celtix.jmstransport" > <jms:JMSNamingProperty name="java.naming.factory.initial" value="org.activemq.jndi.ActiveMQInitialContextFactory" /> <jms:JMSNamingProperty name="java.naming.provider.url" value="tcp://localhost:61616" /> </jms:address> </port> </service> ... <definitions>
Example 9.5. Consumer Endpoint with a Defined Endpoint Name
<beans xmlns:cxfbc="http://servicemix.apache.org/cxfbc/1.0"
xmlns:widgets="http://demos.widgetVendor.com"
... >
...
<cxfbc:consumer wsdl="/wsdl/widget.wsdl"
endpoint="WidgetEasternSalesService" />
...
</beans>
Specifying the target endpoint
- If you explicitly specify an endpoint using both the
targetService
attribute and thetargetEndpoint
attribute, the ESB will use that endpoint. - If you only specify a value for the
targetService
attribute, the ESB will attempt to find an appropriate endpoint on the specified service. - If you specify an the name of an interface that can accept the message using the
targetInterface
attribute, the ESB will attempt to locate an endpoint that implements the specified interface and direct the messages to it. - If you do not use any of the target attributes, the ESB will use the values used in configuring the endpoint's service name and endpoint name to determine the target endpoint.
Example 9.6. Consumer Endpoint Configuration Specifying a Target Endpoint
<beans xmlns:cxfbc="http://servicemix.apache.org/cxfbc/1.0" xmlns:widgets="http://demos.widgetVendor.com" ... > ... <cxfbc:consumer wsdl="/wsdl/widget.wsdl" targetEndpoint="WidgetSalesTargetPort" targetService="widgets:WidgetSalesTargetService" /> ... </beans>