gpt4 book ai didi

java - 将 Azure 服务总线与 Spring Boot 集成

转载 作者:行者123 更新时间:2023-12-03 06:11:17 28 4
gpt4 key购买 nike

我使用 Spring Boot 为主题创建一个新的订阅者,并向其应用自定义过滤器。我使用连接字符串建立连接来创建订阅者。

虽然我已成功创建订阅者,但自定义过滤器尚未应用。我的要求是创建一个新的订阅者并向其附加关联自定义过滤器。

此外,我还使用了service-bus的v7.14.0。示例代码如下:

final String connectionString = "";

// create connection
ServiceBusAdministrationClient adminClient = new ServiceBusAdministrationClientBuilder()
.connectionString(connectionString)
.buildClient();

// create filter
CreateRuleOptions ruleOptions = new CreateRuleOptions();
CorrelationRuleFilter correlationFilter = new CorrelationRuleFilter();
correlationFilter.getProperties().put("X number", "12345"); // Here I set custom correlation filter.
ruleOptions.setFilter(correlationFilter);

//create subscription
CreateSubscriptionOptions subscriptionOptions = new CreateSubscriptionOptions()
.setAutoDeleteOnIdle(Duration.ofDays(7))
.setMaxDeliveryCount(10)
.setDefaultMessageTimeToLive(Duration.ofDays(2))
.setUserMetadata("some metadata");

adminClient.createSubscription("topic name", "subscriber", "Rule name", subscriptionOptions, ruleOptions);

最佳答案

Although I have successfully created the Subscriber, the custom filter has not been applied. My requirement is to create a new Subscriber and attach a correlation custom filter to it.

我在我的环境中进行了尝试并得到了相同的结果。

最初,我尝试使用 Java 代码创建具有相关过滤器的订阅,但是,它仅创建了一个订阅而没有创建过滤器,我们可能无法在 Java 中执行此操作,或者它可能是一个错误。

要进行交替,请先创建订阅,然后您可以使用下面的 Java 代码来创建相关过滤器。

代码:

import com.azure.messaging.servicebus.administration.*;
import com.azure.messaging.servicebus.administration.models.CorrelationRuleFilter;
import com.azure.messaging.servicebus.administration.models.CreateRuleOptions;


public final class App {
public static void main(String[] args) {
final String connectionString = "xxxxx";
ServiceBusAdministrationClient adminClient = new ServiceBusAdministrationClientBuilder().connectionString(connectionString).buildClient();

CorrelationRuleFilter filter = new CorrelationRuleFilter();
filter.getProperties().put("eventType", "order.created");
filter.getProperties().put("eventTypeVersion", 1);
filter.getProperties().put("label","important");

adminClient.createRule("topic326","rule326","subscription326",new CreateRuleOptions(filter));
}
}

输出: enter image description here

引用:

CorrelationFilter Class | Microsoft Learn

关于java - 将 Azure 服务总线与 Spring Boot 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76751964/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com