ibe*_*dev 6 masstransit azureservicebus azure-servicebus-queues azure-servicebus-topics azure-servicebus-subscriptions
我正在实现一个库,供事件的发布者和消费者通过 Azure 服务总线进行通信,我认为 MassTransit 可能是一个不错的选择。
我能够用它发布多个事件,并且如果我让 MassTransit 创建它需要的任何主题,并通过在消费者上仅指定我指定队列名称的 3 种事件类型的接收器端点,则可以让多个消费者毫无问题地接收它们。
消费者示例:
var busControl =
Bus.Factory.CreateUsingAzureServiceBus(
cfg =>
{
CreateAzureServiceBusHost(cfg, serviceBusUri, serviceBusKeyName, serviceBusKey);
cfg.ReceiveEndpoint(queueName, endpoint =>
{
foreach (var eventDtoType in eventsTypes)
{
var adapterType = typeof(EventHandlerAdapter<>).MakeGenericType(eventDtoType);
var resolvedType = sp.GetService(adapterType);
endpoint.Consumer(adapterType, type => resolvedType);
}
});
});
Run Code Online (Sandbox Code Playgroud)
请注意,我将 an 指定为使用者,EventHandlerAdapterType<TEvent>因为我有一个适配器来从 MassTransit 中抽象事件处理程序。但这与这个问题无关。
发布者配置如下:
var busControl =
Bus.Factory.CreateUsingAzureServiceBus(
cfg =>
{
CreateAzureServiceBusHost(cfg, serviceBusUri, serviceBusKeyName, serviceBusKey);
});
Run Code Online (Sandbox Code Playgroud)
问题是我需要使用这个与创建自己主题的系统集成的库,并且它具有安全性(只有某些应用程序可以发布到它,只有某些应用程序可以读取已发布到该主题的消息)
因此,我需要为想要发布特定主题事件的发布者以及想要阅读特定主题的消费者创建一个令牌 sas。不过,令牌的创建超出了这个问题的范围。
我的解决方案尝试:我在Azure服务总线中准备以下场景: - 创建主题topic-attempt-one(启用分区,但不确定是否相关) -subscription-attempt-one在其中创建订阅topic-attempt-one
- 在主题上创建具有仅发送权限的共享访问策略SamplePublishOnly- 创建共享SampleReadOnly具有只听权限的主题的访问策略
我修改了我的示例,以便发布者按照规定使用密钥和 keyName,SamplePublishOnly并且两个消费者按照规定使用密钥和 keyNameSampleReadOnly
在发布者上,我将其配置为对 3 个不同的事件使用相同的主题。
var busControl =
Bus.Factory.CreateUsingAzureServiceBus(
cfg =>
{
CreateAzureServiceBusHost(cfg, serviceBusUri, serviceBusKeyName, serviceBusKey);
// Here I add the same topic name for the 3 event types I want to publish.
cfg.Message<IEventOne>(topology =>
{
topology.SetEntityName("topic-attempt-one");
});
cfg.Message<IEventTwo>(topology =>
{
topology.SetEntityName("topic-attempt-one");
});
cfg.Message<IEventThree>(topology =>
{
topology.SetEntityName("topic-attempt-one");
});
});
Run Code Online (Sandbox Code Playgroud)
我为消费者配置了三个消息的接收端点(消费者一有一个队列名称,消费者二有一个不同的队列名称),此外还准确指定了要使用的主题和订阅。
var busControl =
Bus.Factory.CreateUsingAzureServiceBus(
cfg =>
{
CreateAzureServiceBusHost(cfg, serviceBusUri, serviceBusKeyName, serviceBusKey);
cfg.ReceiveEndpoint(queueName, endpoint =>
{
//I specify the topic and subscription name that is already created in ServiceBus
endpoint.Subscribe("topic-attempt-one", "subscription-attempt-one");
foreach (var eventDtoType in eventsTypes)
{
var adapterType = typeof(EventHandlerAdapter<>).MakeGenericType(eventDtoType);
var resolvedType = sp.GetService(adapterType);
endpoint.Consumer(adapterType, type => resolvedType);
}
});
});
var busControlWrapper = new BusControlWrapper(busControl);
return busControlWrapper;
Run Code Online (Sandbox Code Playgroud)
消费者现在无法启动公交车。我认为存在一个权限问题:
Microsoft.Azure.ServiceBus.UnauthorizedException: Manage,EntityRead claims required for this operation. TrackingId:2d6953d0-c8e1-4bdc-bed5-cc6e5d2d1f9e_G27, SystemTcker:sunnyatticsoftware.servicebus.windows.net:topic-attempt-one, Timestamp:2020-03-07T20:26:38
Run Code Online (Sandbox Code Playgroud)
好的,所以我决定在 Azure 服务总线中为每个消费者手动创建两个队列,希望 MassTransit 可以在需要不同消息时创建虚拟队列。- 创建queue-one
- 创建共享访问策略,声明仅监听,我调用它QueueReadOnly并尝试使用它的 keyName 和密钥。
没有什么。一个不同的错误,但仍然无法使其工作
Microsoft.Azure.ServiceBus.UnauthorizedException: claim is empty. TrackingId:9e344a3f-d40a-475d-bf61-7aae274ed2d1_G17, SystemTracker:sunnyatticsoftware.servicebus.windows.net:topic-attempt-one, Timestamp:2020-03-07T20:40:33
Run Code Online (Sandbox Code Playgroud)
这是有道理的,因为我告诉它使用特定的主题和订阅,但不使用具有读取权限的令牌,因为我已将其替换为队列令牌。
问题
Manage完全权限令牌,因为我不希望消费者在某个主题上发布内容,那么其他人如何处理权限?谢谢!
PS:我发现了类似的问题,但不幸的是它并没有解决我的问题。 如何指定与 MassTransit 一起使用的 Azure 服务总线主题
更新1
我发现了这个:Is it possible to use MassTransit 3 with Azure Service Bus without Manage Permission Policy?
如果最新的 6.2 版本仍然如此,则可以解释为什么我会收到这些错误。如果我不能使用“管理”以外的任何声明,那真是太遗憾了。那么,公共交通没有细粒度的权限吗?如何阻止具有Manage令牌的应用程序读取它不应该读取的消息?
如果无法创建主题、订阅或队列等实体,是否可以使用大众交通?
我猜我缺乏很多知识,所以任何链接也将不胜感激!
| 归档时间: |
|
| 查看次数: |
1922 次 |
| 最近记录: |