微服务未收到RabbitMq消息

时间:2019-06-10 08:38:28

标签: c# .net rabbitmq microservices masstransit

将新用户添加到IdentiyServerService时,将调用以下MassTransit代码:

        var newUserCreated = new UserCreated
        {
            UserId = userId.ToString(),
            Name = user.Name
        };
        await _bus.Publish(newUserCreated);

我的目的地是我的ProfileService通过RabbitMq收到此事件。

我的RabbitMq(IdentiyServerService)中的Startup.cs配置

private static void ConfigureBus(ContainerBuilder builder)
    {
        builder.Register(context =>
        {
            return Bus.Factory.CreateUsingRabbitMq(config =>
            {
                var host = config.Host(new Uri("rabbitmq://localhost"), h =>
                {
                    h.Username("guest");
                    h.Password("guest");
                });
            });
        }).As<IBus, IBusControl, IPublishEndpoint>().SingleInstance();
    }

我这样开公车

//Startup.cs IdentityServerService
var container = containerBuilder.Build();
var busControl = container.Resolve<IBusControl>();
busControl.Start();

我的ProfileService中的配置看起来几乎相同。区别在于,我在Startup.cs(ProfileService)

中添加了一个使用者
                config.ReceiveEndpoint(host, "user_queue", ep =>
                {
                    ep.Consumer<UserCreatedConsumer>(); // The consumer is registered explicitly this time.
                });

我也添加了一个IConsumer

public class UserCreatedConsumer : IConsumer<UserCreated>
{
    public Task Consume(ConsumeContext<UserCreated> context)
    {
        var user = context.Message;
        Debug.WriteLine("My debug string here");
        return TaskUtil.Completed;
    }
}

当我创建新用户时,邮件会收到RabbitMq(发布率提高)。但是随后什么也没有发生。 Queued messages中的邮件总数不变。

我有两个连接(我期望IdentityServerServiceProfileService)并且我有不同的队列(我只期望一个:user_queue

enter image description here

IConsumer中实现IdentityServerService时,会收到消息。

我没有错误日志,警告或其他信息。

无论如何... 1)为什么ProfileService没有收到该消息? 2)为什么我有这么多队列?

如果您需要更多信息...请告诉

修改

当我在RabbitMq管理中发送消息时,我的ProfileService收到了一条消息,但是现在出现以下错误

MassTransit.Messages Error: 0 : R-FAULT 
rabbitmq://localhost/user_queue_new  Value cannot be null.
Parameter name: source, 
System.Runtime.Serialization.SerializationException: An exception occurred while deserializing the message envelope ---> System.ArgumentNullException: Value cannot be null.
Parameter name: source

0 个答案:

没有答案
相关问题