Example #1
0
        public static void Main(string[] args)
        {
            const String queueName = "lucasQueue";
            const String bindingKey = "key";
            const int limit = 10;
            String data = "";
            BroadCastService broadCastService = new BroadCastService();
            BroadCastServiceClient broadCastServiceClient = new BroadCastServiceClient();

            //Test 1
            testPubhlishAndSubscribeAllMsg(broadCastService, broadCastServiceClient, queueName, data, bindingKey, limit);

            //Test 2
            data = System.Environment.MachineName + " " + new DateTime().Date;
            testPubhlishAndSubscribeOneMsg(broadCastService, broadCastServiceClient, queueName, data, bindingKey);
        }
Example #2
0
        public static void Main(string[] args)
        {
            const String           queueName              = "lucasQueue";
            const String           bindingKey             = "key";
            const int              limit                  = 10;
            String                 data                   = "";
            BroadCastService       broadCastService       = new BroadCastService();
            BroadCastServiceClient broadCastServiceClient = new BroadCastServiceClient();

            //Test 1
            testPubhlishAndSubscribeAllMsg(broadCastService, broadCastServiceClient, queueName, data, bindingKey, limit);

            //Test 2
            data = System.Environment.MachineName + " " + new DateTime().Date;
            testPubhlishAndSubscribeOneMsg(broadCastService, broadCastServiceClient, queueName, data, bindingKey);
        }
Example #3
0
        private static void testPubhlishAndSubscribeOneMsg( BroadCastService broadCastService
            , BroadCastServiceClient broadCastServiceClient, String queueName
            , String data,String bindingKey )
        {
            Console.WriteLine("\n");

            /* Publishing single message on the queue */
            broadCastService.publishData(queueName, data, bindingKey);

            /* Getting the first message from the queue */
            BasicDeliverEventArgs basicDeliverEventArgs = broadCastServiceClient.subscribeFirstMessage(queueName, bindingKey, 100);
            var message1 = Encoding.UTF8.GetString(((BasicDeliverEventArgs)basicDeliverEventArgs).Body);
            var routingKey1 = ((BasicDeliverEventArgs)basicDeliverEventArgs).RoutingKey;
            Console.WriteLine(" Received Msg: '{0}' key :{1} on Queue :{2}", message1, routingKey1, queueName);

            /* removing one queue from amqp server*/
            broadCastServiceClient.clearQueue(queueName);
        }
Example #4
0
        private static void testPubhlishAndSubscribeOneMsg(BroadCastService broadCastService
                                                           , BroadCastServiceClient broadCastServiceClient, String queueName
                                                           , String data, String bindingKey)
        {
            Console.WriteLine("\n");

            /* Publishing single message on the queue */
            broadCastService.publishData(queueName, data, bindingKey);

            /* Getting the first message from the queue */
            BasicDeliverEventArgs basicDeliverEventArgs = broadCastServiceClient.subscribeFirstMessage(queueName, bindingKey, 100);
            var message1    = Encoding.UTF8.GetString(((BasicDeliverEventArgs)basicDeliverEventArgs).Body);
            var routingKey1 = ((BasicDeliverEventArgs)basicDeliverEventArgs).RoutingKey;

            Console.WriteLine(" Received Msg: '{0}' key :{1} on Queue :{2}", message1, routingKey1, queueName);

            /* removing one queue from amqp server*/
            broadCastServiceClient.clearQueue(queueName);
        }
Example #5
0
        private static void testPubhlishAndSubscribeAllMsg(BroadCastService broadCastService
                                                           , BroadCastServiceClient broadCastServiceClient, String queueName
                                                           , String data, String bindingKey, int limit)
        {
            /* Publishing mulitple message on the queue */
            for (int i = 0; i < limit; i++)
            {
                data = System.Environment.MachineName + " " + new DateTime().Date + " " + i;
                broadCastService.publishData(queueName + i, data + "-0", bindingKey + i);
                broadCastService.publishData(queueName + i, data + "-1", bindingKey + i);
                broadCastService.publishData(queueName + i, data + "-2", bindingKey + i);
                broadCastService.publishData(queueName + i, data + "-3", bindingKey + i);
                broadCastService.publishData(queueName + i, data + "-4", bindingKey + i);
                broadCastService.publishData(queueName + i, data + "-5", bindingKey + i);
            }


            /* Getting the all message from the queue */
            for (int i = 0; i < limit; i++)
            {
                Console.WriteLine("\n");
                List <BasicDeliverEventArgs> listData = broadCastServiceClient.subscribeAllData(queueName + i, bindingKey + i, 100);
                for (int j = 0; j < listData.Count; j++)
                {
                    object ea         = (BasicDeliverEventArgs)listData[j];
                    var    message    = Encoding.UTF8.GetString(((BasicDeliverEventArgs)ea).Body);
                    var    routingKey = ((BasicDeliverEventArgs)ea).RoutingKey;
                    Console.WriteLine(" Received Msg: '{0}' key :{1} on Queue :{2}", message, routingKey, queueName + i);
                }
            }


            /* removing all the queue from amqp server*/
            Console.WriteLine("\n");
            for (int i = 0; i < limit; i++)
            {
                broadCastServiceClient.clearQueue(queueName + i);
                Console.WriteLine("Deleting Queue '{0}'", queueName + i);
            }
        }
Example #6
0
        private static void testPubhlishAndSubscribeAllMsg(BroadCastService broadCastService
         , BroadCastServiceClient broadCastServiceClient, String queueName
         , String data, String bindingKey, int limit)
        {
            /* Publishing mulitple message on the queue */
            for (int i = 0; i < limit; i++)
            {
                data = System.Environment.MachineName + " " + new DateTime().Date + " " + i;
                broadCastService.publishData(queueName + i, data + "-0", bindingKey + i);
                broadCastService.publishData(queueName + i, data + "-1", bindingKey + i);
                broadCastService.publishData(queueName + i, data + "-2", bindingKey + i);
                broadCastService.publishData(queueName + i, data + "-3", bindingKey + i);
                broadCastService.publishData(queueName + i, data + "-4", bindingKey + i);
                broadCastService.publishData(queueName + i, data + "-5", bindingKey + i);
            }

            /* Getting the all message from the queue */
            for (int i = 0; i < limit; i++)
            {
                Console.WriteLine("\n");
                List<BasicDeliverEventArgs> listData = broadCastServiceClient.subscribeAllData(queueName + i, bindingKey + i, 100);
                for (int j = 0; j < listData.Count; j++)
                {
                    object ea = (BasicDeliverEventArgs)listData[j];
                    var message = Encoding.UTF8.GetString(((BasicDeliverEventArgs)ea).Body);
                    var routingKey = ((BasicDeliverEventArgs)ea).RoutingKey;
                    Console.WriteLine(" Received Msg: '{0}' key :{1} on Queue :{2}", message, routingKey, queueName + i);
                }
            }

            /* removing all the queue from amqp server*/
            Console.WriteLine("\n");
            for (int i = 0; i < limit; i++)
            {
                broadCastServiceClient.clearQueue(queueName + i);
                Console.WriteLine("Deleting Queue '{0}'", queueName + i);
            }
        }