如何通过ClientID和Token使用camel-azure-servebus

rsaldnfx  于 2023-06-22  发布在  Apache
关注(0)|答案(1)|浏览(79)

我正在ActiveMQ中运行Camel,试图连接到Azure服务总线队列,但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 (free service)的数据

w6mmgewl

w6mmgewl1#

不知何故,我已经能够解决连接问题。部分要感谢Chat-GPT提供了一个基于com.azure.identity jar源代码的示例。
我不会列出所有的dependent.jars,因为有很多...

<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>

在连接时,我现在得到一个有效令牌;

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软件包有冲突。Azure的东西需要asm-1.0.2,这似乎打破了嵌入式码头服务器;

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>

相关问题