如何使用camel-azure-servicebus与ClientID和Token

huangapple go评论68阅读模式
英文:

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.

    &lt;endpoint id=&quot;azureQueueEndpoint&quot; uri=&quot;azureServiceBusComponent:iris.705d3ce1-xxxx-4fdf-acb3-xxxxxx&quot; /&gt;
    
    &lt;route id=&quot;Elexon_IRIS_Route&quot;&gt;
    	&lt;from uri=&quot;azureQueueEndpoint&quot; /&gt;
    	&lt;to uri=&quot;localAMQ:topic:IRIS-Elexon&quot;/&gt;
    &lt;/route&gt;
    
    &lt;bean id=&quot;azureServiceBusComponent&quot; class=&quot;org.apache.camel.component.azure.servicebus.ServiceBusComponent&quot;&gt;
    		
    	&lt;property name=&quot;configuration&quot;&gt;
    		&lt;bean class=&quot;org.apache.camel.component.azure.servicebus.ServiceBusConfiguration&quot;&gt;
    			&lt;property name=&quot;connectionString&quot; value=&quot;Endpoint=https://elexon-iris.servicebus.windows.net/iris.705d3ce1-xxxx-4fdf-acb3-xxxxxx;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=?????;EntityPath=iris.705d3ce1-xxxx-4fdf-acb3-xxxxxx&quot; /&gt;
    		&lt;/bean&gt;
    	&lt;/property&gt;
    &lt;/bean&gt;

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 | {&quot;az.sdk.message&quot;:&quot;Non-retryable error occurred in AMQP receive link.&quot;,&quot;exception&quot;:&quot;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]&quot;,&quot;linkName&quot;:&quot;n/a&quot;,&quot;entityPath&quot;:&quot;n/a&quot;}
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...

&lt;endpoint id=&quot;azureQueueEndpoint&quot; uri=&quot;azureServiceBusComponent:iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx&quot; /&gt;

&lt;route id=&quot;Elexon_IRIS_Route&quot;&gt;
	&lt;from uri=&quot;azureQueueEndpoint&quot; /&gt;
	&lt;to uri=&quot;localAMQ:topic:IRIS-Elexon&quot;/&gt;
&lt;/route&gt;

&lt;bean id=&quot;azureServiceBusComponent&quot; class=&quot;org.apache.camel.component.azure.servicebus.ServiceBusComponent&quot;&gt;	
	&lt;property name=&quot;configuration&quot;&gt;
		&lt;bean class=&quot;org.apache.camel.component.azure.servicebus.ServiceBusConfiguration&quot;&gt;
			&lt;property name=&quot;tokenCredential&quot; ref=&quot;azauth&quot; /&gt;
			&lt;property name=&quot;fullyQualifiedNamespace&quot; value=&quot;elexon-iris.servicebus.windows.net&quot; /&gt;
		&lt;/bean&gt;
	&lt;/property&gt;
&lt;/bean&gt;

&lt;bean id=&quot;azauth&quot; class=&quot;com.azure.identity.ClientSecretCredential&quot;&gt;
	&lt;constructor-arg value=&quot;AZURE_TENANT_ID&quot;/&gt;
	&lt;constructor-arg value=&quot;CLIENT_ID&quot;/&gt;
	&lt;constructor-arg value=&quot;CLIENT_SECRET&quot;/&gt;
		&lt;constructor-arg&gt;
			&lt;bean class=&quot;com.azure.identity.implementation.IdentityClientOptions&quot;/&gt;
	&lt;/constructor-arg&gt;
&lt;/bean&gt;

On connection I now get a valid token;

 INFO | Azure Identity =&gt; getToken() result for scopes [https://servicebus.azure.net/.default]: SUCCESS
 INFO | {&quot;az.sdk.message&quot;:&quot;Scheduling refresh token task.&quot;,&quot;scopes&quot;:&quot;https://servicebus.azure.net/.default&quot;}
 INFO | {&quot;az.sdk.message&quot;:&quot;Creating a new receiver link.&quot;,&quot;connectionId&quot;:&quot;MF_77e428_1686394354332&quot;,&quot;sessionName&quot;:&quot;iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx&quot;,&quot;linkName&quot;:&quot;iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx_76bf6f_1686394354961&quot;}
 INFO | {&quot;az.sdk.message&quot;:&quot;Setting next AMQP receive link.&quot;,&quot;linkName&quot;:&quot;iris.705d3ce1-xxxx-4fdf-acb3-0fcb836d2bc9_76bf6f_1686394354961&quot;,&quot;entityPath&quot;:&quot;iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx&quot;}
 INFO | {&quot;az.sdk.message&quot;:&quot;Returning existing receive link.&quot;,&quot;connectionId&quot;:&quot;MF_77e428_1686394354332&quot;,&quot;linkName&quot;:&quot;iris.705d3ce1-690e-4fdf-acb3-0fcb836d2bc9_76bf6f_1686394354961&quot;,&quot;entityPath&quot;:&quot;iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx&quot;}
 INFO | {&quot;az.sdk.message&quot;:&quot;onLinkRemoteOpen&quot;,&quot;connectionId&quot;:&quot;MF_77e428_1686394354332&quot;,&quot;entityPath&quot;:&quot;iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx&quot;,&quot;linkName&quot;:&quot;iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx_76bf6f_1686394354961&quot;,&quot;remoteSource&quot;:&quot;Source{address=&#39;iris.705d3ce1-xxxx-4fdf-acb3-xxxxxxxx&#39;, durable=NONE, expiryPolicy=SESSION_END, timeout=0, dynamic=false, dynamicNodeProperties=null, distributionMode=null, filter=null, defaultOutcome=null, outcomes=null, capabilities=null}&quot;}

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 &lt;convertBodyTo type=&quot;java.lang.String&quot;/&gt; to the route like and turning into valid JSON;

&lt;route id=&quot;Elexon_IRIS_Route&quot;&gt;
   	&lt;from uri=&quot;azureQueueEndpoint&quot; /&gt;
   	&lt;convertBodyTo type=&quot;java.lang.String&quot;/&gt;
    &lt;unmarshal&gt;&lt;json/&gt;&lt;/unmarshal&gt;
   	&lt;to uri=&quot;localAMQ:queue:IRIS-Elexon&quot;/&gt;
&lt;/route&gt;

huangapple
  • 本文由 发表于 2023年6月5日 21:48:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76407092.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定