我们有不同的后端(主要是SOAP,因此我将重点讨论这个),每个后端都有自己的特性(安全性、默认超时、错误处理等)。
另一方面,我们有大量集成服务,它们协调对这些后端的调用。例如,服务A首先使用SOAP请求调用“后端1”,然后调用“后端2”。最后,它使用两个后端的响应来创建响应。
有很多像“服务A”这样的服务,每个服务都有一个单独的编排。它们中的每一个都是一个单独的项目,具有自己的存储库,并作为一个小的Spring单元部署。
假设10个服务中有4个调用“后端1”。他们不一定要调用相同的服务“后端1",但他们都需要实现这个后端的细节。例如,发送特定的头、特定的安全令牌、对此后端使用重试策略等。
为了避免每个集成服务重复用于“后端1”或“后端2”的特定,我希望以某种方式封装这些特定的。
因为我们使用Apache,所以我假设I可以使用自定义Camel组件来完成这个任务。但是,由于组件通常集成新类型的后端,所以我不知道是否应该这样做,或者这是否是个坏主意。我的后端类型(例如SOAP)已经作为组件存在,我只需要用具体的内容包装它们。
例如,为了“封装”SOAP后端,我可以创建一个自定义组件,将该组件委托给CXF组件,以创建具有此后端的公共细节(头、安全性等)的具体服务端点。
在骆驼路线上,端点可能会看起来像这样
MyBackend://serviceUri?option1=value1在引擎盖下它会创造
cxf://serviceUri?backendSpecific1=valueA&backendSpecific2=valueB&option1=value1或者是否有其他更合适的扩展点可用于此用例?
发布于 2018-07-09 23:47:33
有一种方法可以在某种程度上实现这一点。它被称为端点重用。让我来介绍一下我通常如何处理这样的问题。
我通常在camel-context.xml中声明我的所有SOAP和JMS端点。然后,我为每个路由创建xml文件,并从其中引用camel-context.xml中定义的端点。
下面是我的camel-context.xml的一个简短示例,注意routeContextRef元素:
<bp:blueprint
xmlns="http://camel.apache.org/schema/blueprint"
xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.2.0 http://aries.apache.org/schemas/blueprint-ext/blueprint-ext-1.2.xsd">
<camelContext id="foo-bar" trace="{{camel.context.trace}}" autoStartup="true" useMDCLogging="true" useBreadcrumb="true" depends-on="jms" threadNamePattern="#camelId#-thread-#counter#" managementNamePattern="#camelId#-#version#" allowUseOriginalMessage="false" streamCache="false">
<routeContextRef ref="foo-bar-routes"/>
<endpoint id="jms-gateway-v1" uri="jms:queue:Foo.Bar.System.Evt.1.0.T" />
<endpoint id="rs-gateway-v1" uri="cxfrs://bean://rs-gateway-impl-v1" />
</camelContext>
然后,我创建了一个foo Broades.xml,并从那里引用了端点,如下所示:
<bp:blueprint xmlns="http://camel.apache.org/schema/blueprint"
xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ers="http://www.fooxml.com/events/resourceitem/service/v1"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<routeContext id="foo-bar-routes">
<!--
This route receives an event from the JMS queue
-->
<route id="jms-gateway-route-v1">
<from ref="jms-gateway-v1" />
<to ref="rs-gateway-v1" />
</route>
</bp:blueprint>因此,简而言之,我将SOAP和JMS组件封装在端点定义中,然后在自己的xml文档中定义的路由中重用这些组件。我可以在另一个XML文件中添加第二条路由,并在该路径中重用端点--只需添加、漂洗和重复。
我知道JavaDSL具有类似的功能,所以使用JavaDSL也是可以实现的。
https://stackoverflow.com/questions/51241936
复制相似问题