当前位置: 首页>>代码示例>>C#>>正文


C# IBus.Publish方法代码示例

本文整理汇总了C#中IBus.Publish方法的典型用法代码示例。如果您正苦于以下问题:C# IBus.Publish方法的具体用法?C# IBus.Publish怎么用?C# IBus.Publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IBus的用法示例。


在下文中一共展示了IBus.Publish方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public void Run(IBus bus, TextWriter w)
        {
            _c.Add(bus.Subscribe<MessageA>(OnMessageA));
            _c.Add(bus.Subscribe<MessageB>(OnMessageB));
            _c.Add(bus.Subscribe<MessageC>(OnMessageC));

            var r = new Random();
            var dict = new Dictionary<int, Func<object>>
                           {
                               {0, () => new MessageA()},
                               {1, () => new MessageB()},
                               {2, () => new MessageC()},
                           };
            int count = 0;
            var sw = Stopwatch.StartNew();
            while (count < 100000)
            {
                bus.Publish(dict[r.Next(0, 3)]());
                count++;
            }

            w.WriteLine("Through {0}", sw.ElapsedMilliseconds);

            while (_aCount != MessageA.Count && _bCount != MessageB.Count && _cCount != MessageC.Count)
            {
                WriteInfo(w);
                Thread.Sleep(1000);
            }
            WriteInfo(w);
        }
开发者ID:mdabbagh88,项目名称:MemBus,代码行数:30,代码来源:Simple.cs

示例2: Run

        public void Run(IBus bus, TextWriter w)
        {
            c.Add(bus.Subscribe<MessageA>(onMessageA));
            c.Add(bus.Subscribe<MessageB>(onMessageB));
            c.Add(bus.Subscribe<MessageC>(onMessageC));

            var r = new Random();
            var dict = new Dictionary<int, Func<object>>
                           {
                               {0, () => new MessageA()},
                               {1, () => new MessageB()},
                               {2, () => new MessageC()},
                           };
            int count = 0;
            var sw = Stopwatch.StartNew();
            while (count < 100000)
            {
                bus.Publish(dict[r.Next(0, 3)]());
                count++;
            }

            w.WriteLine("Through {0}", sw.ElapsedMilliseconds);

            count = 0;
            while (count < 10)
            {
                w.WriteLine("From MsgA:{0}({1}), B:{2}({3}), C:{4}({5})", aCount, MessageA.Count, bCount,
                            MessageB.Count, cCount, MessageC.Count);
                Thread.Sleep(1000);
                count++;
            }
        }
开发者ID:pixelmeister,项目名称:MemBus,代码行数:32,代码来源:Simple.cs

示例3: Start

        static void Start(IBus bus)
        {
            Console.WriteLine("This will publish IEvent, EventMessage, and AnotherEventMessage alternately.");
            Console.WriteLine("Press 'Enter' to publish a message.To exit, Ctrl + C");

            var nextEventToPublish = 0;
            while (Console.ReadLine() != null)
            {
                var eventId = Guid.NewGuid();

                switch (nextEventToPublish)
                {
                    case 0:
                        bus.Publish<IMyEvent>(m =>
                        {
                            m.EventId = eventId;
                            m.Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null;
                            m.Duration = TimeSpan.FromSeconds(99999D);
                        });

                        nextEventToPublish = 1;

                        break;
                    case 1:
                        var eventMessage = new EventMessage
                        {
                            EventId = eventId,
                            Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null,
                            Duration = TimeSpan.FromSeconds(99999D)
                        };

                        bus.Publish(eventMessage);

                        nextEventToPublish = 2;

                        break;
                    default:
                        var anotherEventMessage = new AnotherEventMessage
                        {
                            EventId = eventId,
                            Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null,
                            Duration = TimeSpan.FromSeconds(99999D)
                        };

                        bus.Publish(anotherEventMessage);

                        nextEventToPublish = 0;

                        break;
                }

                Console.WriteLine("Published event with Id {0}.", eventId);

                Console.WriteLine("==========================================================================");
            }
        }
开发者ID:ramonsmits,项目名称:supportcode,代码行数:56,代码来源:Program.cs

示例4: SendMessages

 public override IEnumerable<Task> SendMessages(IBus bus)
 {
     for (var i = 0; i < NumMessagesToSend/8; i++)
     {
         yield return bus.Publish(new FooEvent());
         yield return bus.Publish(new BarEvent());
         yield return bus.Publish(new BazEvent());
         yield return bus.Publish(new QuxEvent());
         Console.Write(".");
     }
     Console.WriteLine();
 }
开发者ID:nblumhardt,项目名称:Nimbus,代码行数:12,代码来源:WhenPublishingManyEventsOfDifferentTypes.cs

示例5: Start

    static void Start(IBus bus)
    {
        Console.WriteLine("Press '1' to publish IEvent");
        Console.WriteLine("Press '2' to publish EventMessage");
        Console.WriteLine("Press '3' to publish AnotherEventMessage");
        Console.WriteLine("Press any other key to exit");
        #region PublishLoop
        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            Console.WriteLine();

            Guid eventId = Guid.NewGuid();
            switch (key.Key)
            {
                case ConsoleKey.D1:
                    bus.Publish<IMyEvent>(m =>
                    {
                        m.EventId = eventId;
                        m.Time = DateTime.Now.Second > 30 ? (DateTime?)DateTime.Now : null;
                        m.Duration = TimeSpan.FromSeconds(99999D);
                    });
                    Console.WriteLine("Published IMyEvent with Id {0}.", eventId);
                    continue;
                case ConsoleKey.D2:
                    EventMessage eventMessage = new EventMessage
                    {
                        EventId = eventId,
                        Time = DateTime.Now.Second > 30 ? (DateTime?)DateTime.Now : null,
                        Duration = TimeSpan.FromSeconds(99999D)
                    };
                    bus.Publish(eventMessage);
                    Console.WriteLine("Published EventMessage with Id {0}.", eventId);
                    continue;
                case ConsoleKey.D3:
                    AnotherEventMessage anotherEventMessage = new AnotherEventMessage
                    {
                        EventId = eventId,
                        Time = DateTime.Now.Second > 30 ? (DateTime?)DateTime.Now : null,
                        Duration = TimeSpan.FromSeconds(99999D)
                    };
                    bus.Publish(anotherEventMessage);
                    Console.WriteLine("Published AnotherEventMessage with Id {0}.", eventId);
                    continue;
                default:
                    return;
            }
        }
        #endregion
    }
开发者ID:odelljl,项目名称:docs.particular.net,代码行数:50,代码来源:Program.cs

示例6: PlaceNewOrder

        private static void PlaceNewOrder(IBus bus)
        {
            var meal = Meals[Random.Next(0, 2)];
            var size = Sizes[Random.Next(0, 3)];

            bus.Publish(new NewOrderMessage(Guid.NewGuid()) { Name = meal, Size = size });
        }
开发者ID:geffzhang,项目名称:ServiceConnect-CSharp,代码行数:7,代码来源:Program.cs

示例7: ConcreteMessage

 void ConcreteMessage(IBus bus)
 {
     #region InstancePublish
     MyEvent message = new MyEvent { SomeProperty = "Hello world" };
     bus.Publish(message);
     #endregion
 }
开发者ID:odelljl,项目名称:docs.particular.net,代码行数:7,代码来源:BasicOperations.cs

示例8: Start

    static void Start(IBus bus)
    {
        Console.WriteLine("Press 'p' to Publish MyEvent");
        Console.WriteLine("Press 's' to SendLocal MyMessage");
        Console.WriteLine("Press any other key to exit");

        while (true)
        {
            var key = Console.ReadKey();
            Console.WriteLine();

            var id = Guid.NewGuid();
            if (key.Key == ConsoleKey.P)
            {
                var myEvent = new MyEvent
                {
                    Id = id,
                };
                bus.Publish(myEvent);
                Console.WriteLine("Published MyEvent with Id {0}.", id);
                continue;
            }
            if (key.Key == ConsoleKey.S)
            {
                var eventMessage = new MyMessage
                {
                    Id = id,
                };
                bus.SendLocal(eventMessage);
                Console.WriteLine("Sent MyMessage with Id {0}.", id);
                continue;
            }
            return;
        }
    }
开发者ID:SimonCropp,项目名称:PubSubRepro,代码行数:35,代码来源:Program.cs

示例9: InterfaceMessage

        void InterfaceMessage(IBus bus)
        {
            #region InterfacePublish
            bus.Publish<IMyEvent>(m => { m.SomeProperty = "Hello world"; });
            #endregion

        }
开发者ID:odelljl,项目名称:docs.particular.net,代码行数:7,代码来源:BasicOperations.cs

示例10: ReplayCommandModule

 public ReplayCommandModule(IBus bus)
 {
     Get["/Replay"] = parameters =>
     {
         bus.Publish(new ReplayCommand());
         return Response.AsJson("Done!");
     };
 }
开发者ID:rjonker1,项目名称:lightstone-data-platform,代码行数:8,代码来源:ReplayCommandModule.cs

示例11: SendMessages

 public override async Task SendMessages(IBus bus, Func<bool> shouldKeepSending)
 {
     while (shouldKeepSending())
     {
         await bus.Publish(new FooEvent());
         IncrementExpectedMessageCount(2);
     }
 }
开发者ID:fenix2222,项目名称:Nimbus,代码行数:8,代码来源:WhenPublishingManyEventsOfTheSameType.cs

示例12: Publish

 public static void Publish(IBus bus)
 {
     foreach (var word in WordLoader.LoadWords())
     {
         Thread.Sleep(10);
         bus.Publish(new WordMessage{ Word = word });
         Console.WriteLine("Published '{0}'", word);
     }
 }
开发者ID:mikehadlow,项目名称:Mike.EasyNetQDemo,代码行数:9,代码来源:Program.cs

示例13: PublishEvent

    static void PublishEvent(IBus bus)
    {
        Guid eventId = Guid.NewGuid();

        bus.Publish<IMyEvent>(m =>
        {
            m.EventId = eventId;
        });
        Console.WriteLine("Event published, id: " + eventId);
    }
开发者ID:cdnico,项目名称:docs.particular.net,代码行数:10,代码来源:CommandSender.cs

示例14: Publish

        static void Publish(int numberOfJobs, IBus bus)
        {
            Console.WriteLine("Publishing {0} jobs", numberOfJobs);

            var jobs = Enumerable.Range(0, numberOfJobs)
                .Select(i => new Job { JobNumber = i })
                .Select(job => bus.Publish(job))
                .ToArray();

            Task.WaitAll(jobs);
        }
开发者ID:nls75,项目名称:RebusSamples,代码行数:11,代码来源:Program.cs

示例15: Initialize

 public void Initialize(IBus bus)
 {
     bus.Subscribe<StartMessage>("id", startMessage =>
     {
         var request = new TestRequestMessage {Text = startMessage.Text};
         bus.Request<TestRequestMessage, TestResponseMessage>(request, response =>
         {
             var endMessage = new EndMessage {Text = response.Text};
             bus.Publish(endMessage);
         });
     });
 }
开发者ID:redsquare,项目名称:EasyNetQ,代码行数:12,代码来源:RequestResponseSaga.cs


注:本文中的IBus.Publish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。