英文:
How do I use camel-azure-servicebus with ClientID & Token
问题
我正在运行Camel,尝试连接到Azure ServiceBus队列,但是org.apache.camel.component.azure.servicebus.ServiceBusConfiguration
似乎只接受一个connectionString
属性。不幸的是,我没有也无法获取连接字符串。
我已分配了ClientID、Tenant ID和Secret。我无法弄清楚如何在我的现有基于XML的配置中实现这一点。我已经尝试从我拥有的详细信息中构建连接字符串,但我认为这是不可能的。
<endpoint id="azureQueueEndpoint" uri="azureServiceBusComponent:iris.705d3ce1-xxxx-4fdf-acb3-xxxxxx" />
<route id="Elexon_IRIS_Route">
<from uri="azureQueueEndpoint" />
<to uri="localAMQ:topic:IRIS-Elexon"/>
</route>
<bean id="azureServiceBusComponent" class="org.apache.camel.component.azure.servicebus.ServiceBusComponent">
<property name="configuration">
<bean class="org.apache.camel.component.azure.servicebus.ServiceBusConfiguration">
<property name="connectionString" value="Endpoint=https://elexon-iris.servicebus.windows.net/iris.705d3ce1-xxxx-4fdf-acb3-xxxxxx;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=?????;EntityPath=iris.705d3ce1-xxxx-4fdf-acb3-xxxxxx" />
</bean>
</property>
</bean>
我对Java不太熟悉,只能理解基于XML的配置。目前,在启动路由时我收到以下错误:
WARN | {"az.sdk.message":"Non-retryable error occurred in AMQP receive link.","exception":"status-code: 401, status-description: InvalidSignature: The token has an invalid signature., errorContext[NAMESPACE: elexon-iris.servicebus.windows.net. ERROR CONTEXT: N/A, PATH: $cbs, REFERENCE_ID: cbs:receiver, LINK_CREDIT: 0]","linkName":"n/a","entityPath":"n/a"}
ERROR | Errors occurred upstream.
我正在尝试连接到ServiceBus并将消息流桥接到ActiveMQ队列。这是使用来自Elexon-IRIS(免费服务)的数据。
英文:
I am running Camel inside ActiveMQ trying to connect to an Azure ServiceBus Queue, but org.apache.camel.component.azure.servicebus.ServiceBusConfiguration
appears only to accept a connectionString
property. Sadly I don't have and can't get a connection string.
I have been allocated a ClientID, Tenant ID, Secret instead. I can't work out how to implement this with my existing xml based configuration. I have tried to craft a connection string from the details I have but I guess this is not possible.
<endpoint id="azureQueueEndpoint" uri="azureServiceBusComponent:iris.705d3ce1-xxxx-4fdf-acb3-xxxxxx" />
<route id="Elexon_IRIS_Route">
<from uri="azureQueueEndpoint" />
<to uri="localAMQ:topic:IRIS-Elexon"/>
</route>
<bean id="azureServiceBusComponent" class="org.apache.camel.component.azure.servicebus.ServiceBusComponent">
<property name="configuration">
<bean class="org.apache.camel.component.azure.servicebus.ServiceBusConfiguration">
<property name="connectionString" value="Endpoint=https://elexon-iris.servicebus.windows.net/iris.705d3ce1-xxxx-4fdf-acb3-xxxxxx;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=?????;EntityPath=iris.705d3ce1-xxxx-4fdf-acb3-xxxxxx" />
</bean>
</property>
</bean>
I'm not great with Java and can only really understand xml based config. Currently I get the following error when starting the route;
WARN | {"az.sdk.message":"Non-retryable error occurred in AMQP receive link.","exception":"status-code: 401, status-description: InvalidSignature: The token has an invalid signature., errorContext[NAMESPACE: elexon-iris.servicebus.windows.net. ERROR CONTEXT: N/A, PATH: $cbs, REFERENCE_ID: cbs:receiver, LINK_CREDIT: 0]","linkName":"n/a","entityPath":"n/a"}
ERROR | Errors occurred upstream.
I am trying to connect to the ServiceBus and bridge the message feed to an ActiveMQ queue. The is using data from Elexon-IRIS (free service)
答案1
得分: 0
已成功解决连接问题,部分归功于 Chat-GPT 提供的基于 com.azure.identity jar 源代码的示例。
不会列出所有的依赖 .jars,因为有很多...
在连接时,我现在获得了有效的令牌:
INFO | Azure Identity => getToken() result for scopes [https://servicebus.azure.net/.default]: SUCCESS
INFO | {"az.sdk.message":"Scheduling refresh token task.","scopes":"https://servicebus.azure.net/.default"}
INFO | {"az.sdk.message":"Creating a new receiver link.","connectionId":"MF_77e428_1686394354332","sessionName":"iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx","linkName":"iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx_76bf6f_1686394354961"}
INFO | {"az.sdk.message":"Setting next AMQP receive link.","linkName":"iris.705d3ce1-xxxx-4fdf-acb3-0fcb836d2bc9_76bf6f_1686394354961","entityPath":"iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx"}
INFO | {"az.sdk.message":"Returning existing receive link.","connectionId":"MF_77e428_1686394354332","linkName":"iris.705d3ce1-690e-4fdf-acb3-0fcb836d2bc9_76bf6f_1686394354961","entityPath":"iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx"}
INFO | {"az.sdk.message":"onLinkRemoteOpen","connectionId":"MF_77e428_1686394354332","entityPath":"iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx","linkName":"iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx_76bf6f_1686394354961","remoteSource":"Source{address='iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx', durable=NONE, expiryPolicy=SESSION_END, timeout=0, dynamic=false, dynamicNodeProperties=null, distributionMode=null, filter=null, defaultOutcome=null, outcomes=null, capabilities=null}"}
现在我有其他问题;我与 ASM packages 有冲突。Azure 部分需要 asm-1.0.2
,似乎会破坏嵌入的 Jetty 服务器:
WARN | Failed startup of context o.e.j.w.WebAppContext@25de8898{/admin,file:///root/apache-activemq-5.18.1/webapps/admin/,UNAVAILABLE}
java.lang.ExceptionInInitializerError: null
at org.eclipse.jetty.annotations.AnnotationConfiguration.createAnnotationParser(AnnotationConfiguration.java:502) ~[jetty-annotations-9.4.51.v20230217.jar:9.4.51.v20230217]
at org.eclipse.jetty.annotations.AnnotationConfiguration.scanForAnnotations(AnnotationConfiguration.java:416) ~[jetty-annotations-9.4.51.v20230217.jar:9.4.51.v20230217]
at org.eclipse.jetty.annotations.AnnotationConfiguration.configure(AnnotationConfiguration.java:346) ~[jetty-annotations-9.4.51.v20230217.jar:9.4.51.v20230217]
这个问题通过删除 asm-1.0.2.jar
和旧的 json-smart.jar 得以解决。
尽管代理已经启动,但最大的问题(留待以后讨论)是当接收消息并尝试将其发送到 AMQ 时出现的错误:
WARN | Cannot determine specific JmsMessage type to use from body class. Will use generic JmsMessage. Body class: com.azure.core.util.BinaryData. If you want to send a POJO then your class might need to implement java.io.Serializable, or you can force a specific type by setting the jmsMessageType option on the JMS endpoint.
通过将 <convertBodyTo type="java.lang.String"/>
添加到路由,并将其转换为有效的 JSON,问题得以解决:
<route id="Elexon_IRIS_Route">
<from uri="azureQueueEndpoint" />
<convertBodyTo type="java.lang.String"/>
<unmarshal><json/></unmarshal>
<to uri="localAMQ:queue:IRIS-Elexon"/>
</route>
英文:
Somehow I have been able to resolve the connection issue. In part thanks to Chat-GPT for providing an example based on the source code from the com.azure.identity jar.
I will not list all the dependant .jars as there are many...
<endpoint id="azureQueueEndpoint" uri="azureServiceBusComponent:iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx" />
<route id="Elexon_IRIS_Route">
<from uri="azureQueueEndpoint" />
<to uri="localAMQ:topic:IRIS-Elexon"/>
</route>
<bean id="azureServiceBusComponent" class="org.apache.camel.component.azure.servicebus.ServiceBusComponent">
<property name="configuration">
<bean class="org.apache.camel.component.azure.servicebus.ServiceBusConfiguration">
<property name="tokenCredential" ref="azauth" />
<property name="fullyQualifiedNamespace" value="elexon-iris.servicebus.windows.net" />
</bean>
</property>
</bean>
<bean id="azauth" class="com.azure.identity.ClientSecretCredential">
<constructor-arg value="AZURE_TENANT_ID"/>
<constructor-arg value="CLIENT_ID"/>
<constructor-arg value="CLIENT_SECRET"/>
<constructor-arg>
<bean class="com.azure.identity.implementation.IdentityClientOptions"/>
</constructor-arg>
</bean>
On connection I now get a valid token;
INFO | Azure Identity => getToken() result for scopes [https://servicebus.azure.net/.default]: SUCCESS
INFO | {"az.sdk.message":"Scheduling refresh token task.","scopes":"https://servicebus.azure.net/.default"}
INFO | {"az.sdk.message":"Creating a new receiver link.","connectionId":"MF_77e428_1686394354332","sessionName":"iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx","linkName":"iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx_76bf6f_1686394354961"}
INFO | {"az.sdk.message":"Setting next AMQP receive link.","linkName":"iris.705d3ce1-xxxx-4fdf-acb3-0fcb836d2bc9_76bf6f_1686394354961","entityPath":"iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx"}
INFO | {"az.sdk.message":"Returning existing receive link.","connectionId":"MF_77e428_1686394354332","linkName":"iris.705d3ce1-690e-4fdf-acb3-0fcb836d2bc9_76bf6f_1686394354961","entityPath":"iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx"}
INFO | {"az.sdk.message":"onLinkRemoteOpen","connectionId":"MF_77e428_1686394354332","entityPath":"iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx","linkName":"iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx_76bf6f_1686394354961","remoteSource":"Source{address='iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx', durable=NONE, expiryPolicy=SESSION_END, timeout=0, dynamic=false, dynamicNodeProperties=null, distributionMode=null, filter=null, defaultOutcome=null, outcomes=null, capabilities=null}"}
I have other problems now though; I have a conflict with the ASM packages. The azure stuff requires asm-1.0.2
which seem to break the embedded jetty server with;
WARN | Failed startup of context o.e.j.w.WebAppContext@25de8898{/admin,file:///root/apache-activemq-5.18.1/webapps/admin/,UNAVAILABLE}
java.lang.ExceptionInInitializerError: null
at org.eclipse.jetty.annotations.AnnotationConfiguration.createAnnotationParser(AnnotationConfiguration.java:502) ~[jetty-annotations-9.4.51.v20230217.jar:9.4.51.v20230217]
at org.eclipse.jetty.annotations.AnnotationConfiguration.scanForAnnotations(AnnotationConfiguration.java:416) ~[jetty-annotations-9.4.51.v20230217.jar:9.4.51.v20230217]
at org.eclipse.jetty.annotations.AnnotationConfiguration.configure(AnnotationConfiguration.java:346) ~[jetty-annotations-9.4.51.v20230217.jar:9.4.51.v20230217]
This was fixed by removing the asm-1.0.2.jar
and old json-smart.jar
Though the broker starts. The biggest problem (for another post) is this error I now get presumably when receiving a message and trying to send it to AMQ:
WARN | Cannot determine specific JmsMessage type to use from body class. Will use generic JmsMessage. Body class: com.azure.core.util.BinaryData. If you want to send a POJO then your class might need to implement java.io.Serializable, or you can force a specific type by setting the jmsMessageType option on the JMS endpoint.
Which was fixed by adding <convertBodyTo type="java.lang.String"/>
to the route like and turning into valid JSON;
<route id="Elexon_IRIS_Route">
<from uri="azureQueueEndpoint" />
<convertBodyTo type="java.lang.String"/>
<unmarshal><json/></unmarshal>
<to uri="localAMQ:queue:IRIS-Elexon"/>
</route>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论