示例#1
0
        public void testCreatingObjects()
        {
            IMessagingBus          bus = MQFactory.Instance.createMessagingBus();
            IMQConnection          serverConnection = null;
            IMQConnection          clientConnection = null;
            IMessageQueue <String> queue            = null;

            try {
                serverConnection = bus.create(new Uri("bnmq://127.0.0.1:3333"));
                ISupplier supplier = serverConnection.createSupplier("TestSupplier");
                queue = supplier.createQueue <String>("myqueues/queue");
                serverConnection.addListener(new TestMQConnectionListener());
                serverConnection.start();

                clientConnection = bus.connect(new Uri("bnmq://127.0.0.1:3333"));
                clientConnection.addListener(new TestMQConnectionListener());
                clientConnection.start();

                IRemoteSupplier remSupplier           = clientConnection.lookup("TestSupplier");
                IRemoteMessageQueue <String> remQueue = remSupplier.lookupQueue <String>("myqueues/queue");
                remQueue.addConsumer(new TestConsumer());
                for (int i = 0; i < 100; i++)
                {
                    IMessage <String> message = queue.createMessage("Hello" + i);
                    queue.sendMessage(message);
                }
                Thread.Sleep(1000);

                try {
                    IRemoteMessageQueue <String> unknownRemQueue = remSupplier.lookupQueue <String>("myqueues/queue1");
                    unknownRemQueue.addConsumer(new TestConsumer());
                    Assert.True(false);
                }
                catch (Exception ex) {
                    Assert.True(ex.ToString().Contains("unknownQueue"));
                }
            }
            finally {
                if (queue != null)
                {
                    queue.stop();
                }
                if (clientConnection != null)
                {
                    clientConnection.close();
                }
                if (serverConnection != null)
                {
                    serverConnection.close();
                }
                if (bus != null)
                {
                    bus.close();
                }
            }
        }
示例#2
0
        protected void doSubscribe()
        {
            Console.WriteLine("Trying to lookup supplier");
            IRemoteSupplier remSupplier = clientConnection.lookup("ExampleSupplier");

            queue = remSupplier.lookupQueue <ExampleMessage>("myqueues/queue");
            Console.WriteLine("Trying to lookup & persistence subscribe consumer");
            queue.addConsumer(new ExampleConsumer(), true);
            Console.WriteLine("Subscribed procedure finished");
        }
示例#3
0
        public void testRPCStyle()
        {
            IMessagingBus          bus = MQFactory.Instance.createMessagingBus();
            IMQConnection          serverConnection = null;
            IMQConnection          clientConnection = null;
            IMessageQueue <String> queue            = null;

            try {
                serverConnection = bus.create(new Uri("bnmq://127.0.0.1:3333"));
                ISupplier supplier = serverConnection.createSupplier("TestSupplier");
                queue = supplier.createQueue <String>("myqueues/queue");
                serverConnection.addListener(new TestMQConnectionListener());
                serverConnection.start();

                clientConnection = bus.connect(new Uri("bnmq://127.0.0.1:3333"));
                clientConnection.addListener(new TestMQConnectionListener());
                clientConnection.start();
                IRemoteSupplier remSupplier           = clientConnection.lookup("TestSupplier");
                IRemoteMessageQueue <String> remQueue = remSupplier.lookupQueue <String>("myqueues/queue");
                remQueue.addConsumer(new TestRPCConsumer());

                String result = queue.call("Hello from Server", "RPC-Consumer", 20);
                Assert.Equals(result, "Hello from RPC Consumer");

                queue.callAsync("Hello from Server 2", "RPC-Consumer", new TestRPCAsyncCallBack(), 20);
                Assert.Equals(result, "Hello from RPC Consumer");
                Thread.Sleep(2000);
            }
            catch (Exception e) {
                Console.WriteLine(e.ToString());
                throw e;
            }
            finally {
                if (queue != null)
                {
                    queue.stop();
                }
                if (clientConnection != null)
                {
                    clientConnection.close();
                }
                if (serverConnection != null)
                {
                    serverConnection.close();
                }
                if (bus != null)
                {
                    bus.close();
                }
            }
        }
示例#4
0
        public void testPersistence()
        {
            IMessagingBus bus = MQFactory.Instance.createMessagingBus();

            IDictionary <string, object> storageProps = new Dictionary <string, object>();

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

            // For SQLite
            //Object obj = Activator.CreateInstance("System.Data.SQLite.SQLiteConnection", "SQLiteConnection");
            //System.Data.SQLite.SQLiteConnection connection = null;
            storageProps.Add("dbAssemblyName", "System.Data.SQLite");
            storageProps.Add("dbConnectionClass", "System.Data.SQLite.SQLiteConnection");
            storageProps.Add("dbConnectionString", "Data Source=test.db3");
            IPersistenceStorage <String> persistStorage = MQFactory.Instance.createPersistenceStorage <String>("SQL", storageProps);

            IMQConnection                     serverConnection = null;
            IMQConnection                     clientConnection = null;
            IMessageQueue <String>            queue            = null;
            IPersistenceQueueStorage <String> queueStorage     = null;

            try {
                serverConnection = bus.create(new Uri("bnmq://127.0.0.1:3333"));
                ISupplier supplier = serverConnection.createSupplier("TestSupplier");
                queueStorage = persistStorage.createQueueStorage("MyQueue");
                queue        = supplier.createQueue <String>("myqueues/queue", queueStorage);
                serverConnection.addListener(new TestMQConnectionListener());
                serverConnection.start();

                clientConnection = bus.connect(new Uri("bnmq://127.0.0.1:3333"));
                clientConnection.addListener(new TestMQConnectionListener());
                clientConnection.start();
                IRemoteSupplier remSupplier           = clientConnection.lookup("TestSupplier");
                IRemoteMessageQueue <String> remQueue = remSupplier.lookupQueue <String>("myqueues/queue");
                remQueue.addConsumer(new TestPersistenceConsumer(), true);
                clientConnection.close();
                clientConnection = null;

                for (int i = 0; i < 10; i++)
                {
                    IMessage <String> mandatoryMessage = queue.createMessage("Mandatory message " + i);
                    mandatoryMessage.Mandatory = true;
                    queue.sendMessage(mandatoryMessage);
                }

                clientConnection = bus.connect(new Uri("bnmq://127.0.0.1:3333"));
                clientConnection.addListener(new TestMQConnectionListener());
                clientConnection.start();
                remSupplier = clientConnection.lookup("TestSupplier");
                remQueue    = remSupplier.lookupQueue <String>("myqueues/queue");
                remQueue.addConsumer(new TestPersistenceConsumer(), true);
                Thread.Sleep(2000);
                //clientConnection.close();
            }
            finally {
                if (queue != null)
                {
                    queue.stop();
                }
                if (queueStorage != null)
                {
                    queueStorage.close();
                }
                if (clientConnection != null)
                {
                    clientConnection.close();
                }
                if (serverConnection != null)
                {
                    serverConnection.close();
                }
                if (bus != null)
                {
                    bus.close();
                }
            }
        }