【问题标题】:how to add custom properties or label/subject for azure servicebus topic messages when using apache camel?使用 apache camel 时如何为 azure servicebus 主题消息添加自定义属性或标签/主题?
【发布时间】:2022-10-05 05:16:25
【问题描述】:

我可以使用此处的示例https://camel.apache.org/components/3.18.x/azure-servicebus-component.html#_azure_servicebus_producer_operations 使用 apache camel 向 azure service bus topic 的特定订阅发送消息。但我无法使用我的代码设置属性.在我的代码下方 -

    from("direct:start")
    .id("producerId")
            .marshal(new JacksonDataFormat(String.class))
    .process(exchange -> {
    exchange.setProperty(ServiceBusConstants.SUBJECT, constant("test"));
    })
    .setProperty("subject", constant("test"))
    .setProperty(ServiceBusConstants.CORRELATION_ID, constant("111111"))
    .setHeader("subject", constant("test"))
    .setHeader("label", constant("test"))
    .setHeader(ServiceBusConstants.SUBJECT, constant("test"))
    .to("azure-servicebus:testTopic?serviceBusType=topic&subscriptionName=testTopic-subscription&producerOperation=sendMessages&connectionString=RAW(Endpoint=sb://blablablablbalabla")
    .log(LoggingLevel.INFO, "Message sent to test topic ${body} and ${headers}")
    .setRouteProperties(propertyDefinitions);

正如您在上面看到的,我已经尝试了所有方法,例如使用“setProperty”和“setHeader”不同的方式。我得到以下回应-

Message sent to test topic "{\"accountId\": \"4471112323123\", \"url\": \"test.com\", \"status\": \"PASS\", \"statusMessage\": \"check if received\"}" and {applicationProperties={label: test}, CamelAzureServiceBusApplicationProperties={Label=test, Subject=test}, CamelAzureServiceBusSubject=test, Content-Type=application/json}

这是我的生产者代码-

Test test = new test(uuid, "test.com", "PASS", "check if received");
ProducerTemplate producerTemplate;
producerTemplate.sendBody(direct:start, test.toString());

我已经通过 azure portal(ui) 发送了一条消息,这看起来像属性:

如果您看到“主题”是“测试”并且有一个自定义属性“测试”具有值“测试”。

当我使用 apache camel 发送它时,我想看到同样的东西。请帮忙。谢谢

【问题讨论】:

标签: java apache-camel azure-servicebus-topics


【解决方案1】:

今天,最新版本的 Camel 无法实现,但它将在下一个版本中发布。

相关票务:https://issues.apache.org/jira/browse/CAMEL-18459

代码:https://github.com/apache/camel/blob/main/components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/ServiceBusProducer.java

这就是它的样子:

from("timer:foo1?period=15000&delay=1000")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        exchange.getIn().setBody("{\"message\":\"hello\"}");
                        exchange.getIn().setHeader(ServiceBusConstants.APPLICATION_PROPERTIES, Map.of("prop1", "value1"));
                    }
                })
                .to("azure-servicebus:demo?serviceBusType=topic&connectionString=RAW(connection-string-here");

【讨论】:

    猜你喜欢
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多