Consumer endpoints play the role of consumer from the vantage point of other endpoints running inside of the ESB. However, from outside of the ESB a consumer endpoint plays the role of a service provider. As shown in Figure 9.1, consumer endpoints listen from incoming requests from external endpoints. When it receives a request, the consumer passes it off to the NMR fro delivery to endpoint that will process the request. If a response is generated, the consumer endpoint delivers the response back to the external endpoint.
![]() | Important |
---|---|
Because consumer endpoint's behave like service providers to external endpoints, you configure the runtime behavior of the transport using the provider-specific WSDL entries. |
To configure a consumer endpoint do the following:
Add a
consumer
element to yourxbean.xml
file.Add a
wsdl
attribute to theconsumer
element.See Specifying the WSDL.
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.See Part III.
The 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.
![]() | Tip |
---|---|
If the WSDL document defines a single service with a single endpoint, then you do not require any additional information to expose a consumer endpoint. |
Example 9.1 shows the minimal configuration for a consumer endpoint.
Example 9.1. Minimal Consumer Endpoint Configuration
<beans xmlns:cxfbc="http://servicemix.apache.org/cxfbc/1.0" ... > ... <cxfbc:consumer wsdl="/wsdl/widget.wsdl" /> ... </beans>
For information on creating a WSDL document see Part I: Defining an Endpoint in WSDL.
If the endpoint's WSDL document defines a single service with a single endpoint, the ESB can easily determine which endpoint to use. It will use the values from the WSDL document to specify the service name, endpoint name and interface name for the instantiated endpoint.
However, if the endpoint's WSDL document defines multiple services or if it defines multiple endpoints for a service, you will need to provide the consumer endpoint with additional information so that it can determine the proper definition to use. What information you need to provide depends on the complexity of the WSDL document. You may need to supply values for both the service name and the endpoint name, or you may only have to supply one of these values.
If the WSDL document contains more than one 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 you would use the configuration shown in Example 9.3.
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>
If the WSDL document's service definition contains more than one endpoint, then you will need to provide a value for the consumer's 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 you would use the configuration shown in Example 9.5.
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>
The consumer endpoint will determine the target endpoint in the following manner:
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 shows the configuration for a consumer endpoint that specifies the target endpoint to use.
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>
![]() | Important |
---|---|
If you specify values for more than one of the target attributes, the consumer endpoint will use the most specific information. |