Пример #1
0
        public void start()
        {
            IMessagingBus bus = MQFactory.Instance.createMessagingBus();


            IMQConnection serverConnection = null;
            IMessageQueue <ExampleMessage>            queue        = null;
            IPersistenceQueueStorage <ExampleMessage> queueStorage = null;
            QueueDispatcher dispatcher = null;

            try {
                serverConnection = bus.create(new Uri("bnmq://127.0.0.1:3333"));
                serverConnection.addListener(new MQConnectionListener());
                ISupplier supplier = serverConnection.createSupplier("ExampleSupplier");
                Console.WriteLine("Supplier created successfully");

                IDictionary <String, Object> storProps = new Dictionary <String, Object>();
                storProps.Add("storageName", "MyMemoryStorage");
                // For InMemoryDB (It's not HSQLDB!)
                IPersistenceStorage <ExampleMessage> persistStorage = MQFactory.Instance.createPersistenceStorage <ExampleMessage>("InMemory", storProps);

                queueStorage = persistStorage.createQueueStorage("MyQueue");
                Console.WriteLine("QueueStorage created successfully");

                queue = supplier.createQueue <ExampleMessage>("myqueues/queue", queueStorage);
                Console.WriteLine("MessageQueue created successfully");

                serverConnection.start();
                Console.WriteLine("Listener created successfully");

                dispatcher = new QueueDispatcher(queue);
                dispatcher.start();
                Console.WriteLine("Example queue dispatcher started successfully");

                Console.WriteLine("Please enter to exit");
                Console.ReadKey();
                Console.WriteLine("Trying to stop example queue dispatcher");
                dispatcher.stop();
            }
            catch (Exception e) {
                Console.WriteLine(e.ToString());
            }
            finally {
                if (serverConnection != null)
                {
                    Console.WriteLine("Trying to close listener");
                    serverConnection.close();
                }

                if (queue != null)
                {
                    Console.WriteLine("Trying to stop queue");
                    queue.stop();
                }

                if (queueStorage != null)
                {
                    Console.WriteLine("Trying to close queue storage");
                    queueStorage.close();
                }

                if (bus != null)
                {
                    Console.WriteLine("Trying to finallize messaging bus");
                    bus.close();
                }
            }
        }
Пример #2
0
        public void start()
        {
            IMessagingBus bus = MQFactory.Instance.createMessagingBus();

            IMQConnection serverConnection  = null;
            IMessageQueue<ExampleMessage> queue = null;
            IPersistenceQueueStorage<ExampleMessage> queueStorage = null;
            QueueDispatcher dispatcher = null;
            try {
                serverConnection  = bus.create(new Uri("bnmq://127.0.0.1:3333"));
                serverConnection.addListener(new MQConnectionListener());
                ISupplier supplier =  serverConnection.createSupplier("ExampleSupplier");
                Console.WriteLine("Supplier created successfully");

                IDictionary<String,Object> storProps = new Dictionary<String,Object>();
                storProps.Add("storageName","MyMemoryStorage");
                // For InMemoryDB (It's not HSQLDB!)
                IPersistenceStorage< ExampleMessage > persistStorage =  MQFactory.Instance.createPersistenceStorage<ExampleMessage>("InMemory",storProps);

                queueStorage = persistStorage.createQueueStorage("MyQueue");
                Console.WriteLine("QueueStorage created successfully");

                queue = supplier.createQueue<ExampleMessage>("myqueues/queue", queueStorage);
                Console.WriteLine("MessageQueue created successfully");

                serverConnection.start();
                Console.WriteLine("Listener created successfully");

                dispatcher = new QueueDispatcher(queue);
                dispatcher.start();
                Console.WriteLine("Example queue dispatcher started successfully");

                Console.WriteLine("Please enter to exit");
                Console.ReadKey();
                Console.WriteLine("Trying to stop example queue dispatcher");
                dispatcher.stop();
            }
            catch (Exception e) {
                Console.WriteLine(e.ToString());
            }
            finally {
                if (serverConnection != null)
                {
                    Console.WriteLine("Trying to close listener");
                    serverConnection.close();
                }

                if(queue!=null)
                {
                    Console.WriteLine("Trying to stop queue");
                    queue.stop();
                }

                if(queueStorage!=null)
                {
                    Console.WriteLine("Trying to close queue storage");
                    queueStorage.close();
                }

                if(bus!=null) {
                    Console.WriteLine("Trying to finallize messaging bus");
                    bus.close();
                }
            }
        }