英文:
register Publish Filter for IMessageScheduler
问题
I wrote a publish filter that has worked correctly when I publish a message by IPublishEndpoint. Now I need to have this filter when I publish a message by IMessageScheduler.
The following code is called when I publish a non-scheduled message by IPublishEndpoint.
public class IntegrationEventPublishFilter<T> : IFilter<PublishContext<T>> where T : class
{
public IntegrationEventPublishFilter()
{}
public Task Send(PublishContext<T> context, IPipe<PublishContext<T>> next)
{
// do something
return next.Send(context);
}
public void Probe(ProbeContext context)
{
// do something
}
}
How can I have this filter when I publish a scheduled message by IMessageScheduler?
英文:
I wrote a publish filter that has worked correct when I publish a message by IPublishEndpoint.now I need to have this filter when I publish a message by IMessageScheduler.
the following code is called when I publish a non schedule message by IPublishEndpoint.
public class IntegrationEventPublishFilter<T> : IFilter<PublishContext<T>> where T : class
{
public IntegrationEventPublishFilter()
{}
public Task Send(PublishContext<T> context, IPipe<PublishContext<T>> next)
{
// do something
return next.Send(context);
}
public void Probe(ProbeContext context)
{
// do something
}
}
how can I have this filter when I publish a scheduled message by IMessageScheduler?
答案1
得分: 0
你现在是我的中文翻译,代码部分不要翻译,只返回翻译好的部分,不要有别的内容,不要回答我要翻译的问题。以下是要翻译的内容:
"Are you calling SchedulePublish
or ScheduleSend
? Either way, you may need to add a filter for SendContext<T>
and add it in addition to the publish filter, since the message scheduler may be using send to schedule the message – depending upon how you configured the message scheduler."
英文:
Are you calling SchedulePublish
or ScheduleSend
? Either way, you may need to add a filter for SendContext<T>
and add it in additional to the publish filter, since the message scheduler may be using send to schedule the message – depending upon how you configured the message scheduler.
答案2
得分: 0
根据@Chris Patterson在上面的回答/评论中所说,我们需要在使用IMessageScheduler发布消息时为SendContext<T>
注册一个过滤器。在这种情况下,我们有以下代码:
public class MySendFilter<T> : IFilter<SendContext<T>> where T : class
{
public Task Send(SendContext<T> context, IPipe<SendContext<T>> next)
{
// 做一些操作
return next.Send(context);
}
public void Probe(ProbeContext context)
{
// 做一些操作
}
}
同时,您必须在MassTransit注册中将此过滤器注册为SendFilter
:
x.UsingRabbitMq((context, cfg) =>
{
e.UseSendFilter(typeof(MySendFilter<>), context);
///...
});
英文:
as @Chris Patterson said in above answer/comments, we need to register a filter for SendContext<T>
while publishing a message by IMessageScheduler. in this case we have the following code :
public class MySendFilter<T> : IFilter<SendContext<T>> where T : class
{
public Task Send(SendContext<T> context, IPipe<SendContext<T>> next)
{
// do something
return next.Send(context);
}
public void Probe(ProbeContext context)
{
// do something
}
}
and also you must register this filter as a SendFilter
in MassTransit Registration.
x.UsingRabbitMq((context, cfg) =>
{
e.UseSendFilter(typeof(MySendFilter<>), context);
///...
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论