Rebus从Bus1的消息处理程序中的Bus2发送

时间:2016-03-18 10:07:36

标签: c# messaging rebus

我必须使用Azure ServiceBus的Rebus总线,但是当我尝试从Bus1的一个消息处理程序中从Bus2发送时,这不起作用。邮件未发送。

有什么想法吗?

修改

1路公交车

[XmlRoot(ElementName="Person")]
public class Data
{
    public string Name { get; set; }
}

巴士2

        string padesQueueAddress = "padesworker";
        int numberOfWorkes = Settings.NumberOfWorkers>0   Settings.NumberOfWorkers:10;

        string errorQueueAddress = string.Format("{0}-error", queueAddress);

        var adapter = new AutofacContainerAdapter(Container);
        Bus = Configure.With(adapter)
             .Logging(l =>  l.Use(UseRaygunRebusLoggingFactory(rayclient,Settings.Debug ? RaygunLoggerLevel.DEBUG :  RaygunLoggerLevel.WARN)))
             .Transport(t => t.UseAzureServiceBus( Settings.AzureQueueConnectionString, queueAddress,AzureServiceBusMode.Standard))                                  
             .Sagas(s => s.StoreInSqlServer(string.IsNullOrWhiteSpace(Settings.RebusSagaSqlConnectionString) ? Settings.AzureSqlConnectionString : Settings.RebusSagaSqlConnectionString, "Saga", "SagaIndex") )
             .Routing(r => r.TypeBased().MapAssemblyOf<SendSmsCommand>(queueAddress).MapAssemblyOf<Unipluss.Sign.Pades.Commands.CreatePadesCommand>(padesQueueAddress))                 
            .Options(o =>
            {
                o.SimpleRetryStrategy(secondLevelRetriesEnabled: true, maxDeliveryAttempts:5,errorQueueAddress: errorQueueAddress);

                o.SetNumberOfWorkers(numberOfWorkes);
                o.SetMaxParallelism(numberOfWorkes);                    

            })                
            .Start();

        await Bus.SendLocal(new HeartBeatCommand());

使用硬编码发送的eventBus发送正在工作,但是当我从Bus1的一个消息处理程序中发送时,消息未被发送(登录记录器表示消息已发送但它确实出现在队列中)

总线2包装在一个包装类中,然后注入到Autofac中,以避免在Autofac中使用IBus接口。

    private  IBus CreateExternalEventBus()
    {

        var eventBus = Configure.With(new BuiltinHandlerActivator())
                .Transport(t => t.UseAzureServiceBus(Settings.EventServiceBusConnectionString, queueAddress+"_event", AzureServiceBusMode.Basic))
                .Logging(x=>x.ColoredConsole(LogLevel.Debug))
                .Options(o =>
                {

                o.LogPipeline(true);
                o.EnableCompression();
                o.EnableEncryption(Settings.RebusEncryptionExternalEvents);
                })
                .Start();

        eventBus.Advanced.Routing.Send("1dd0f6f9422146048516a30f00aef4e5",new Unipluss.Sign.Events.Entities.DocumentCancledEvent() {CancledMessage = "test",DocumentId = Guid.NewGuid()});

        return eventBus;

    }

然后在Bus1中的多个消息处理程序中使用IExternalEventsBus。

1 个答案:

答案 0 :(得分:0)

好的......让我看看我是否明白这一点(如果我错了请纠正我):

您的流程中有两个总线实例:

  1. 使用具有 <nav class="menubar" id="menubar"> <div class="listItems"> <div class="listItem">Personal</div> <div class="listItem">Business</div> <div class="listItem">Career</div> <div class="listItem">Sign In</div> <div class="listItem">Learn More</div> <div class="listItem"><span class="glyphicon glyphicon-align-justify"></span></div> </div> </nav> <div id="container"> <div class="untop"> <div id="untop_align"> <div id="div">Gaining global recognition has never been this easy</div> <div style="font-size: 16px; line-height: 25px; margin-top: 30px; font-weight: 500">Brandme is a digital marketing platform that helps promote your business or skill to a large base</div> <div class="sign_btn"><button class="btn">Start your journey here</button></div> </div> </div> </div> <div class="container-cover-cover"> <div class="container-cover"> <div class="container"> <div class="row"> <div class="col-md-8"> <div class="sample"> <div class="container"> <div class="row"> <div class="col-md-2"><img src ="" class="imagesfaces" style="display: inline-block;position: relative;"></div> <div class="col-md-10"> <div class="names-samples"></div> <div class='positions'></div> <div></div> </div> </div> </div> </div> </div> <div class="col-md-4"> <div id="side"> <div id="sideDescription"> </div> <div id="sideAuthor"> </div> </div> </div> </div> </div> </div> </div> <script type="text/javascript"> var collapse = function(){ $(document).ready(function(){ $(window).resize(function(){ var width = $(window).width(); if(width < 700){ $('#menubar').hide(); } else{ $('#menubar').show(); } }) }) } var imageSize = function(){ $(".imagesfaces").width("80"); } collapse(); imageSize() </script> 指定值的输入队列的人,此处未包含此内容。
  2. 另一个(&#34;外部事件总线&#34;),其输入队列的值由queueAddress指定,您也不在此处。
  3. 您的总线实例的目的似乎是第一个用于协调应用程序内的东西,而第二个用于将事件路由到外部的侦听器 - 这就是您所谓的{{ 3}},因为它将根据消息内容的某些值来路由消息(在本例中为queueAddress+"_event")。

    现在您遇到错误:当总线(1)从其自己的一个消息处理程序中使用总线(2)时,似乎没有发送路由消息。

    您从documentProviderId发布的代码中找不到您调用的ExternalEventsBus方法,但我可以告诉您,带有签名Send的方法只会发送消息如果public Task Send(object message, DocumentProvider documentProvider)不为空。

    1. 您是否确认连接字符串确实带有值?
    2. 为什么documentProvider.RebusQueueConnectionString中有_connectionString字段?您是否应该在创建总线时使用它?
    3. 每次拨打公交车时,你还记得ExternalEventsBus(即await bus.Send(...)异步操作的结果吗?