예제 #1
0
 void IServiceConfig.ConfigureBus()
 {
     ShortBus.Bus.Configure
     .PersistTo(new MongoPersistProvider(mongoAddress, MongoDataBaseName.UseExisting("ShortBus")))
     .MyEndPoint(new ShortBus.Configuration.EndPoint()
     {
         EndPointAddress = endPointAddress
         , EndPointType  = ShortBus.Publish.EndPointTypeOptions.Publisher
         , Name          = ShortBus.Bus.ApplicationName
     })
     .MaxThreads(4);
 }
예제 #2
0
 void IServiceConfig.ConfigureBus()
 {
     ShortBus.Bus.Configure
     .PersistTo(new MongoPersistProvider(mongoAddress, MongoDataBaseName.UseExisting("ShortBus")))
     .MyEndPoint(new ShortBus.Configuration.EndPoint()
     {
         EndPointAddress = endPointAddress
         , EndPointType  = ShortBus.Publish.EndPointTypeOptions.Agent
         , Name          = ShortBus.Bus.ApplicationName
     })
     .MaxThreads(4)
     .RegisterEndpoint("Default", new RESTEndPoint(new RESTSettings(@"http://localhost:9876", ShortBus.Publish.EndPointTypeOptions.Publisher)))
     .RouteMessage <ShortBus.TestMessage>("Default", false);
 }
예제 #3
0
        void IServiceConfig.ConfigureBus()
        {
            ShortBus.Bus.Configure
            .PersistTo(new MongoPersistProvider(mongoAddress, MongoDataBaseName.UseExisting("ShortBus")))
            .MyEndPoint(new ShortBus.Configuration.EndPoint()
            {
                EndPointAddress = endPointAddress
                , Name          = ShortBus.Bus.ApplicationName
                , EndPointType  = ShortBus.Publish.EndPointTypeOptions.Subscriber
            })
            .MaxThreads(4)
            .RegisterEndpoint("Default", new RESTEndPoint(new RESTSettings(pubEndPointAddress, ShortBus.Publish.EndPointTypeOptions.Publisher)))
            .SubscribeToMessage <ShortBus.TestMessage>("Default")

            .RegisterMessageHandler <ShortBus.TestMessage>(new TestHandler());
        }
예제 #4
0
        private static void TestPublish()
        {
            //            new MongoPersist(new MongoPersistSettings() {
            //                Collection = "source", ConnectionString = @"mongodb://127.0.0.1:27017", DB = Bus.ApplicationName
            //            })
            //                 , new MongoPersist(new MongoPersistSettings() {
            //    Collection = "config", ConnectionString = @"mongodb://127.0.0.1:27017", DB = Bus.ApplicationName
            //}))


            Bus.Configure
            .PersistTo(new MongoPersistProvider(@"mongodb://127.0.0.1:27017", MongoDataBaseName.UseExisting("ShortBus")))
            .MaxThreads(1)

            .MyEndPoint(new ShortBus.Configuration.EndPoint()
            {
                EndPointAddress = @"http://*****:*****@"http://localhost:9873", ShortBus.Publish.EndPointTypeOptions.Agent)))
            .RouteMessage <ShortBus.TestMessage>("Default", false);

            Bus.OnStarted       += onStarted;
            Bus.OnProcessing    += onProcessing;
            Bus.OnStalled       += onStalled;
            Bus.OnThreadStarted += onThreadStarted;
            Bus.Start();
            //Bus.SendMessageDirect<TestMessage>(new TestMessage() { Property = string.Format("Thread {0}, Iteration {1}", 0, 0) });

            for (int i = 1; i <= 4; i++)
            {
                Task t = null;
                if (t == null || t.IsCompleted)
                {
                    //t = new Thread(PublishNext);

                    //capture i during the loop, since publishnext is running from the facotry, it may begin
                    //after i has been incremeneted.
                    int q = i;

                    t = Task.Run(() => {
                        for (int g = 1; g <= 5; g++)
                        {
                            Bus.SendMessage <TestMessage>(new TestMessage()
                            {
                                Property = string.Format("Thread {0}, Iteration {1}", q, g)
                            });
                        }
                        Console.WriteLine("Done {0}", q);
                    });
                }
            }



            //messageSendTimer.AutoReset = false;
            //messageSendTimer.Enabled = true;
            //messageSendTimer.Interval = 1000;
            //messageSendTimer.Elapsed += MessageSendTimer_Elapsed;
            //messageSendTimer.Start();

            Console.WriteLine("Press any key to stop: ");
            Console.ReadKey();
        }