Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在CQRS中使用RabbitMQ的微服务中的两个服务之间传输数据?_C#_Asp.net Core_.net Core_Rabbitmq - Fatal编程技术网

C# 如何在CQRS中使用RabbitMQ的微服务中的两个服务之间传输数据?

C# 如何在CQRS中使用RabbitMQ的微服务中的两个服务之间传输数据?,c#,asp.net-core,.net-core,rabbitmq,C#,Asp.net Core,.net Core,Rabbitmq,在CQR中,有3种类型:事件、命令、查询 我已经准备了一些关于github的例子。他们只是为两种类型配置RabbitMQ发布服务器:事件、命令 示例:Service.A,Service.B 服务A需要根据id从服务B中选择一些信息 在CQRS中,我使用查询类型,我希望将数据发送到Service.B并获得Service.B的结果 我可以使用rabbitMQ或HTTP客户机吗 public async Task PublishAsync<TEvent>(TEvent _event, I

在CQR中,有3种类型:事件、命令、查询 我已经准备了一些关于github的例子。他们只是为两种类型配置RabbitMQ发布服务器:事件、命令

示例:Service.A,Service.B 服务A需要根据id从服务B中选择一些信息

在CQRS中,我使用查询类型,我希望将数据发送到Service.B并获得Service.B的结果

我可以使用rabbitMQ或HTTP客户机吗

 public async Task PublishAsync<TEvent>(TEvent _event, ICorrelationContext context) where TEvent : IEvent
    {
        var eventName = _event.GetType().Name;
        _logger.LogInformation($"[Published an event] : '{eventName}'");

        await _busClient.PublishAsync(_event, ctx => ctx.UseMessageContext(context)
            .UsePublishConfiguration(p => p.WithRoutingKey(GetRoutingKey(_event))));
    }

 public async Task SendAsync<TCommand>(TCommand command, ICorrelationContext context) where TCommand : ICommand
    {
        var commandName = command.GetType().Name;
        _logger.LogInformation($"[Sent a command] : '{commandName}'"); ;

        await _busClient.PublishAsync(command, ctx => ctx.UseMessageContext(context)
            .UsePublishConfiguration(p => p.WithRoutingKey(GetRoutingKey(command))));   
    }
公共异步任务PublishAsync(TEvent\u事件,ICorrelationContext上下文),其中TEvent:IEvent { var eventName=\u event.GetType().Name; _logger.LogInformation($“[发布的事件]:'{eventName}'”; wait _busClient.PublishAsync(_事件,ctx=>ctx.UseMessageContext(上下文) .UsePublishConfiguration(p=>p.WithRoutingKey(GetRoutingKey(_事件))); } 公共异步任务SendAsync(TCommand命令,ICorrelationContext上下文),其中TCommand:ICommand { var commandName=command.GetType().Name; _logger.LogInformation($“[发送命令]:'{commandName}'”; wait_busClient.PublishAsync(命令,ctx=>ctx.UseMessageContext(上下文) .UsePublishConfiguration(p=>p.WithRoutingKey(GetRoutingKey(command))); }