static void Main(string[] args)
        {
            string host = "localhost";

            var rabbitMQManager = new RabbitMqManager(host);

            bool newMessage = false;

            var connection = rabbitMQManager.Factory.CreateConnection();
            var channel    = connection.CreateModel();

            rabbitMQManager.SubscribeQueue(channel, QueueNames.HELLO_WORLD, (message) =>
            {
                Console.WriteLine($">>> Received message: '{message}' <<<");
                newMessage = true;
            });

            Console.WriteLine("Welcome in ClientOne application.");

            while (true)
            {
                if (newMessage)
                {
                    Console.Write("Enter your login or quit via 'q': ");
                    var userMessage = Console.ReadLine();
                    if (userMessage == "q")
                    {
                        return;
                    }
                    rabbitMQManager.SendMessage(QueueNames.HELLO_MIKE, userMessage);
                    newMessage = false;
                }
            }
        }
Esempio n. 2
0
        public ActionResult Save(UserViewModel vm)
        {
            var manager = new RabbitMqManager <RegisteredUserEvent>();

            manager.Send(new RegisteredUserEvent
            {
                User = MapUser(vm)
            });

            return(View());
        }
Esempio n. 3
0
        public IActionResult RegisterOrder(OrderViewModel model)
        {
            var registerOrderCommand = new RegisterOrder(model);

            //Send RegisterOrderCommand
            using (var rabbitMqManager = new RabbitMqManager())
            {
                rabbitMqManager.SendRegisterOrderCommand(registerOrderCommand);
            }

            return(View("Thanks"));
        }
        public void Send()
        {
            RabbitMqConfig.RabbitMqSetting = new RabbitMqSetting();
            RabbitMqConfig.RabbitMqSetting.RabbitMqConnection = "amqp://*****:*****@192.168.0.144:5672";
            RabbitMqManager.Register();

            string        businessName = "test_mq";
            List <string> mqTests      = new List <string>();

            mqTests.Add("测试11");
            mqTests.Add("测试21");
            mqTests.Add("测试31");
            RabbitMqHelper.Send(businessName, mqTests);
        }
        public void Send()
        {
            RabbitMqConfig.RabbitMqSetting = new RabbitMqSetting();
            RabbitMqConfig.RabbitMqSetting.RabbitMqConnection = "amqp://*****:*****@192.168.0.144:5672";
            RabbitMqManager.Register();

            string        businessName = "test_mq";
            List <string> mqTests      = new List <string>();

            mqTests.Add("测试1");
            mqTests.Add("测试2");
            mqTests.Add("测试3");
            RabbitMqHelper.Send(businessName, mqTests);
        }
Esempio n. 6
0
 public async Task StartAsync(CancellationToken cancellationToken)
 {
     while (!cancellationToken.IsCancellationRequested)
     {
         try
         {
             var rabbitManager = new RabbitMqManager <RegisteredUserEvent>();
             rabbitManager.Consume(RabbitMqConstants.RegisterQueue, SaveMsgIntoDatabaseAsync);
         }catch (Exception e)
         {
             Console.WriteLine(e);
         }
         await Task.Delay(_milisecondsDelay, cancellationToken);
     }
 }
Esempio n. 7
0
        public void TestMethod()
        {
            var registerUserCommand = new Messages.RegisterUserCommand(
                new UserViewModel
            {
                FirstName = "Jan",
                LastName  = "Kowalski",
                Address   = "Street 23",
                Age       = 23,
                IdNumber  = 2323232
            });

            using (var rabbitMqManager = new RabbitMqManager())
            {
                rabbitMqManager.SendRegisterUserCommand(registerUserCommand);
            }
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            string hostName        = "localhost";
            bool   newMessage      = false;
            var    rabbitMQManager = new RabbitMqManager(hostName);


            var connection = rabbitMQManager.Factory.CreateConnection();
            var channel    = connection.CreateModel();

            rabbitMQManager.SubscribeQueue(channel, QueueNames.HELLO_MIKE, (message) =>
            {
                Console.WriteLine($">>> User's login is : '{message}' <<<");
                newMessage = true;
            });

            while (true)
            {
                Console.WriteLine(">>> Press key to continue or type 'q' to exist app. <<<");
                string userMessage = Console.ReadLine();

                if (userMessage == "q")
                {
                    return;
                }

                Console.WriteLine("[Start, sending user invitation.]");
                try
                {
                    rabbitMQManager.SendMessage(QueueNames.HELLO_WORLD, "Hello, user, introduce yourself!");
                    while (newMessage == false)
                    {
                    }

                    newMessage = false;
                    Console.WriteLine("[Done]");
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"[Something went wrong: {ex.Message}]");
                    Console.ReadKey();
                    return;
                }
            }
        }
        public void GetMessage()
        {
            RabbitMqConfig.RabbitMqSetting = new RabbitMqSetting();
            RabbitMqConfig.RabbitMqSetting.RabbitMqConnection = "amqp://*****:*****@192.168.0.144:5672";
            RabbitMqManager.Register();

            string businessName = "test_mq";

            //var r=RabbitMqHelper.GetMessage(businessName, true);
            //var r1 = RabbitMqHelper.GetMessage(businessName, true);

            //var r2 = RabbitMqHelper.GetMessage(businessName, false);
            RabbitMqHelper.Received(businessName, fun, "direct", (string e) =>
            {
                var cc = e;
            });


            //var r3 = RabbitMqHelper.GetMessage(businessName, false);

            //RabbitMqHelper.BasicAck(r3.DeliveryTag,true);
            Thread.Sleep(6000);
        }
Esempio n. 10
0
 public RegisteredOrderCommandConsumer(
     RabbitMqManager rabbitMqManager)
 {
     this._rabbitMqManager = rabbitMqManager;
 }
Esempio n. 11
0
 public static void Init()
 {
     RabbitMqConfig.RabbitMqSetting = new RabbitMqSetting();
     RabbitMqConfig.RabbitMqSetting.RabbitMqConnection = "amqp://*****:*****@192.168.0.144:5672";
     RabbitMqManager.Register();
 }