Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/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
Asp.net mvc Masstransit无法处理正确的值_Asp.net Mvc_Masstransit - Fatal编程技术网

Asp.net mvc Masstransit无法处理正确的值

Asp.net mvc Masstransit无法处理正确的值,asp.net-mvc,masstransit,Asp.net Mvc,Masstransit,我用一个简单的例子玩MassTransit,我不知道我做错了什么,因为我没有收到正确的数据。 我有一个简单的asp.net-mvc应用程序,在HomeController中有以下代码 public class TweetCreatedCommand : Command { public readonly string Message; public readonly DateTime Timestamp; public readonly Guid TweetId;

我用一个简单的例子玩MassTransit,我不知道我做错了什么,因为我没有收到正确的数据。 我有一个简单的asp.net-mvc应用程序,在HomeController中有以下代码

public class TweetCreatedCommand : Command
{
    public readonly string Message;
    public readonly DateTime Timestamp;
    public readonly Guid TweetId;
    public readonly string Who;

    public TweetCreatedCommand(Guid tweetId, string message, DateTime timeStamp, string who)
    {
        TweetId = tweetId;
        Message = message;
        Timestamp = timeStamp;
        Who = who;
    }
}

public ActionResult Index()
    {
        TweetCreatedCommand data;

        Bus.Initialize(sbc =>
        {
            sbc.UseMsmq();
            sbc.VerifyMsmqConfiguration();
            sbc.UseMulticastSubscriptionClient();
            sbc.ReceiveFrom("msmq://localhost/test_queue");
            sbc.Subscribe(subs =>
            {
                subs.Handler<TweetCreatedCommand>(msg => data = new TweetCreatedCommand(msg.TweetId, msg.Message,msg.Timestamp,msg.Who));
            });
        });

        Bus.Instance.Publish(new TweetCreatedCommand(Guid.NewGuid(),"foo!",DateTime.Now,"CDA"));

                    ViewData.Model = data;

        return View();
    }
公共类TweetCreatedCommand:命令
{
公共只读字符串消息;
公共只读日期时间时间戳;
公共只读Guid TweetId;
公共只读字符串Who;
公共TweetCreatedCommand(Guid tweetId、字符串消息、日期时间戳、字符串who)
{
TweetId=TweetId;
消息=消息;
时间戳=时间戳;
谁=谁;
}
}
公共行动结果索引()
{
TweetCreatedCommand数据;
总线初始化(sbc=>
{
sbc.usemmq();
sbc.VerifyMsmqConfiguration();
使用MulticastSubscriptionClient();
sbc.从(”msmq://localhost/test_queue");
订阅(subs=>
{
Handler(msg=>data=newTweetCreatedCommand(msg.TweetId,msg.Message,msg.Timestamp,msg.Who));
});
});
Publish(新TweetCreatedCommand(Guid.NewGuid(),“foo!”,DateTime.Now,“CDA”);
ViewData.Model=数据;
返回视图();
}
如果调试此代码,我可以看到TweetCreatedCommand是如何发布的,并且MSMQ队列中的数据是正常的,但是当处理程序接收到数据时: TweetCreatedCommand.TweetId是:00000000-0000-0000-0000-000000000000,它应该是另一个东西 TweetCreatedCommand.消息为空,应为“foo!” TweetCreatedCommand.TimeStamp是01/01/01 谁是空的,它应该是“CDA”

怎么了


任何帮助都将不胜感激

MassTransit的默认序列化仅适用于属性。尝试将只读字段更改为属性,序列化程序应正确填充数据。如果需要只读字段,请更改为
BinarySerializer
(默认为JSON)。

MassTransit的默认序列化仅适用于属性。尝试将只读字段更改为属性,序列化程序应正确填充数据。如果需要只读字段,请更改为
BinarySerializer
(默认为JSON)。

非常感谢您,现在它可以完美地更改只读字段。如果我尝试使用UseBarySerializer,它将无法工作。它在发布时调用TweetCreatedCommand构造函数,但在发布后不会再次调用构造函数,因此变量数据为空;我自己也没有因为任何原因使用过BinarySerializer,我确信在它周围有一些额外的陷阱,只是没有出现在我的脑海中。此外,请查看规范:大多数都是针对每个序列化程序运行的。非常感谢,现在它可以完美地更改只读字段。如果我尝试使用UseBinarySerializer,它将不起作用。它在发布时调用TweetCreatedCommand构造函数,但在发布后不会再次调用构造函数,因此变量数据为空;我自己也没有因为任何原因使用过BinarySerializer,我确信在它周围有一些额外的陷阱,只是没有出现在我的脑海中。此外,请查看规范:大多数规范将针对每个序列化程序运行。