我已经用RabbitMq总线创建了服务。 现在,我正在尝试向该总线添加活动(我尝试了发现的每个注册选项)
private void ConfigureBus(IServiceCollectionConfigurator configurator)
{
configurator.AddActivity(typeof(StepAcitivity));
configurator.AddActivitiesFromNamespaceContaining<StepAcitivity>();
configurator.AddActivity<StepAcitivity, StepArguments, StepLog>();
configurator.AddConsumer<PingConsumer>();
}
我还在容器上注册了StepAcitivity:
services.AddScoped<StepAcitivity>();
通过另一项服务: 首先:测试按预期方式运行的ping请求/响应:
IRequestClient<IPingRequest, IPingResponse> client =
busControl.CreateRequestClient<IPingRequest, IPingResponse>(serviceAddress, TimeSpan.FromSeconds(10));
IPingResponse s = await client.Request(request);
第二: 创建并执行活动
string address = config.GetValue<string>("executorAddress");
Uri sendAddress = new Uri($"queue:{address}");
RoutingSlipBuilder builder = new RoutingSlipBuilder(NewId.NextGuid());
builder.AddActivity("SetepA", sendAddress);
builder.AddActivity("StepB", sendAddress);
builder.AddActivity("StepC", sendAddress);
RoutingSlip routingSlip = builder.Build();
return routingSlip;
执行:
await bus.Execute(routingSlip);
ping请求/响应按预期运行,但routingSlip不会失败,但在活动侧我没有接到任何电话的问题。 在rabbitMQ管理处,看到该消息已移至WorkerService_skipped队列。
await bus.Execute(routingSlip)
的呼叫没有中断?
我的masstransit版本是:6.2.3 我的工作人员服务探针:
{
"resultId": "a4984523-5ffc-4ff4-8ceb-498029dbfeff",
"probeId": "561351df-42da-44a7-83ce-29a467966663",
"startTimestamp": "2020-07-06T12:51:32.0106524Z",
"duration": "00:00:00.0427169",
"host": {
"machineName": "SLAVAF-LAP",
"processName": "WorkerService",
"processId": 38212,
"assembly": "WorkerService",
"assemblyVersion": "1.0.0.0",
"frameworkVersion": "3.1.5",
"greenPipesVersion": "3.0.1.0",
"operatingSystemVersion": "Microsoft Windows NT 6.2.9200.0"
},
"results": {
"bus": {
"address": "rabbitmq://localhost:0/SLAVAFLAP_WorkerService_bus_x37yyyd4rz1m1wcfbdcndk4enp?temporary=true",
"host": {
"Type": "RabbitMQ",
"Host": "localhost",
"Port": 5672,
"VirtualHost": "/",
"Username": "slava",
"Password": "****",
"Heartbeat": 0,
"Ssl": false,
"connected": true,
"receiveEndpoint": [
{
"name": "WorkerService",
"started": true,
"transport": {
"type": "RabbitMQ",
"ExchangeName": "WorkerService",
"ExchangeArguments": [],
"ExchangeType": "fanout",
"Durable": true,
"AutoDelete": false,
"QueueName": "WorkerService",
"Exclusive": false,
"QueueArguments": [
[
"x-queue-type",
{}
]
],
"BindingArguments": [],
"PrefetchCount": 16,
"PurgeOnStartup": false,
"ExclusiveConsumer": false,
"NoAck": false,
"BindQueue": true,
"ConsumeArguments": [],
"topology": {
"exchange": [
{
"Name": "WorkerService",
"Type": "fanout",
"Durable": true,
"AutoDelete": false
},
{
"Name": "Common.Messages.Ping:IPingRequest",
"Type": "fanout",
"Durable": true,
"AutoDelete": false
}
],
"queue": {
"Name": "WorkerService",
"Durable": true,
"AutoDelete": false,
"Exclusive": false,
"argument": {
"key": "x-queue-type",
"value": "quorum"
}
},
"exchange-binding": {
"Source": "Common.Messages.Ping:IPingRequest",
"Destination": "WorkerService"
},
"queue-binding": {
"Source": "WorkerService",
"Destination": "WorkerService"
}
}
},
"filters": [
{
"filterType": "deadLetter",
"filters": {
"filterType": "dead-letter"
}
},
{
"filterType": "rescue",
"filters": [
{
"filterType": "generateFault"
},
{
"filterType": "moveFault"
}
]
},
{
"filterType": "deserialize",
"deserializers": {
"json": {
"contentType": "application/vnd.masstransit+json"
},
"bson": {
"contentType": "application/vnd.masstransit+bson"
},
"xml": {
"contentType": "application/vnd.masstransit+xml"
}
},
"consumePipe": {
"filters": {
"filterType": "dispatchPipe",
"outputType": "MassTransit.ConsumeContext<Common.Messages.Ping.IPingRequest>",
"filters": {
"filterType": "MessageFilter",
"Type": "Common.Messages.Ping.IPingRequest"
},
"consumer": {
"type": "WorkerService.Consumers.PingConsumer",
"consumerFactory": {
"source": "scope",
"consumerType": "WorkerService.Consumers.PingConsumer",
"provider": "dependencyInjection"
},
"filters": {
"filterType": "split",
"ConsumerType": "WorkerService.Consumers.PingConsumer",
"filters": {
"filterType": "ScopedLoggingFilter"
}
},
"consume": {
"method": "Consume(ConsumeContext<Common.Messages.Ping.IPingRequest> context)"
}
}
}
}
}
]
},
{
"name": "SLAVAFLAP_WorkerService_bus_x37yyyd4rz1m1wcfbdcndk4enp",
"started": true,
"transport": {
"type": "RabbitMQ",
"ExchangeName": "SLAVAFLAP_WorkerService_bus_x37yyyd4rz1m1wcfbdcndk4enp",
"ExchangeArguments": [],
"ExchangeType": "fanout",
"Durable": false,
"AutoDelete": true,
"QueueName": "SLAVAFLAP_WorkerService_bus_x37yyyd4rz1m1wcfbdcndk4enp",
"Exclusive": false,
"QueueExpiration": "00:01:00",
"QueueArguments": [],
"BindingArguments": [],
"PrefetchCount": 16,
"PurgeOnStartup": false,
"ExclusiveConsumer": false,
"NoAck": false,
"BindQueue": true,
"ConsumeArguments": [],
"topology": {
"exchange": {
"Name": "SLAVAFLAP_WorkerService_bus_x37yyyd4rz1m1wcfbdcndk4enp",
"Type": "fanout",
"Durable": false,
"AutoDelete": true
},
"queue": {
"Name": "SLAVAFLAP_WorkerService_bus_x37yyyd4rz1m1wcfbdcndk4enp",
"Durable": false,
"AutoDelete": false,
"Exclusive": false,
"argument": {
"key": "x-expires",
"value": 60000
}
},
"queue-binding": {
"Source": "SLAVAFLAP_WorkerService_bus_x37yyyd4rz1m1wcfbdcndk4enp",
"Destination": "SLAVAFLAP_WorkerService_bus_x37yyyd4rz1m1wcfbdcndk4enp"
}
}
},
"filters": [
{
"filterType": "deadLetter",
"filters": {
"filterType": "dead-letter"
}
},
{
"filterType": "rescue",
"filters": [
{
"filterType": "generateFault"
},
{
"filterType": "moveFault"
}
]
},
{
"filterType": "deserialize",
"deserializers": {
"json": {
"contentType": "application/vnd.masstransit+json"
},
"bson": {
"contentType": "application/vnd.masstransit+bson"
},
"xml": {
"contentType": "application/vnd.masstransit+xml"
}
},
"consumePipe": {}
}
]
}
]
}
}
}
}
答案 0 :(得分:0)
每个活动都需要一个单独的端点来执行,并且如果活动支持补偿,则还需要一个附加端点来进行补偿。您不能在同一端点上配置活动,并且不应与其他服务共享这些端点。
使用AddActivity()足以配置容器,您无需在活动中调用AddScoped。
此外,您可以使用ConfigureEndpoints并传递注册上下文以配置所有活动,sagas和使用者的总线端点。
您所包含的探针(很好,谢谢)表明,您只有一个接收端点WorkerService,该端点具有处理
IPingRequest
消息的使用者。