Ejemplo n.º 1
0
        static void ReceiveDemo()
        {
            // demonstrate receiving - Receive processes whatever messages happen to be on the queue at the time of the call

            Console.WriteLine("\nPress a key to read message/s");
            Console.ReadLine();

            IBus bus = new BusBuilder()
                       .WithLogging(new FileLogger())
                       .InstallMsmqIfNeeded()
                       .DefineErrorQueue("MiniBus.errors")
                       .DefineReadQueue("MiniBus.messages1")
                       .CreateLocalQueuesAutomatically()
                       .EnlistInAmbientTransactions()
                       .JsonSerialization()
                       .NumberOfRetries(3)
                       .CreateBus();

            // pass true to have a message fail and moved to the error queue
            bus.RegisterHandler(new PersonHandler(false));

            bus.Receive <Person>();

            Console.WriteLine("\nPress a key to exit");
            Console.ReadLine();
            bus.Dispose();
        }
Ejemplo n.º 2
0
        public Passenger(int _pid, bool _isMissionary) // TODO: call this from main with data received from args[]
        {
            this.PID    = _pid;
            this._TYPE_ = _isMissionary ? PassengerType.Missionary : PassengerType.Cannibal;

            // create a bus for sending messages
            IBus bus = new BusBuilder()
                       .WithLogging(new ConsoleLogger())
                       .DefineErrorQueue("Passenger.errors")
                       .DefineWriteQueue("Boat")
                       .CreateLocalQueuesAutomatically()
                       .JsonSerialization()

                       .CreateBus();

            // create your message type
            var msg = new Message {
                PID = this.PID, Value = (int)_TYPE_
            };

            // send it
            bus.Send(msg);

            // create a bus for receiving messages
            bus = new BusBuilder()
                  .WithLogging(new ConsoleLogger())
                  .DefineErrorQueue("Passenger.errors")
                  .DefineReadQueue("Passenger." + PID)
                  //.DefineWriteQueue("Boat")
                  .CreateLocalQueuesAutomatically()
                  .JsonSerialization()
                  .CreateBus();

            // register one or more message handlers
            bus.RegisterHandler <bool>(new ResponseHandler());
            // process messages on the read queue synchronously
            bus.Receive <bool>();

            // process messages on the read queue asynchronously
            //bus.ReceiveAsync<PlaceOrder>();

            // DIE in handler
        }