在连接现有Web服务以处理MQMessage时,我希望能够将消息序列化到数据库,然后将其转换为请求对象并传递给服务端点。如果在我的apphost文件中给出此代码,我该怎么做?
var mqServer = container.Resolve<IMessageService>();
//todo: would like to log the message here, instead of the Service, or Global filter
mqServer.RegisterHandler<LeadInformation>(ServiceController.ExecuteMessage);
mqServer.Start();
更新
这是我希望实施的内容
var mqServer = container.Resolve<IMessageService>();
mqServer.RegisterHandler<LeadInformation>(m =>
{
var db = container.Resolve<IFrontEndRepository>();
db.SaveMessage(m as Message);
return ServiceController.ExecuteMessage(m);
});
mqServer.Start();
这有什么缺点吗?
谢谢你, 斯蒂芬
答案 0 :(得分:1)
您可以将信息保存在RegisterHandler
中mqServer.RegisterHandler<LeadInformation>(m =>
{
var db = container.Resolve<IFrontEndRepository>();
db.SaveMessage(m as Message);
return ServiceController.ExecuteMessage(m);
});
如果您愿意,可以使用RequestFilter:
mqServer.RequestFilter = m =>
{
var db = container.Resolve<IFrontEndRepository>();
db.SaveMessage(m as Message);
return m;
});