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(); } } }
public void testPTPSession() { IMessagingBus bus = MQFactory.Instance.createMessagingBus(); IMQConnection serverConnection = null; IMQConnection clientConnection = null; IPTPSession <String> ptpClientSession = null; IPTPSession <String> ptpServerSession = null; try { serverConnection = bus.create(new Uri("bnmq://127.0.0.1:3333")); ptpServerSession = serverConnection.createPTPSession <String>("serverPTP", "ptpSimpleSession"); ptpServerSession.addListener(new TestPTPSessionListener()); serverConnection.start(); clientConnection = bus.connect(new Uri("bnmq://127.0.0.1:3333")); ptpClientSession = clientConnection.createPTPSession <String>("clientPTP", "ptpSimpleSession"); ptpClientSession.addListener(new TestPTPSessionListener()); clientConnection.start(); string result = ptpClientSession.call("Hello from PTP Client", 20); Assert.Equals(result, "Hello from RPC/PTP"); ptpClientSession.callAsync("Hello from Server 2", new TestRPCAsyncCallBack(), 20); Thread.Sleep(2000); } catch (Exception e) { Console.WriteLine(e.ToString()); throw e; } finally { if (ptpClientSession != null) { ptpClientSession.close(); } if (ptpServerSession != null) { ptpServerSession.close(); } if (clientConnection != null) { clientConnection.close(); } if (serverConnection != null) { serverConnection.close(); } if (bus != null) { bus.close(); } } }
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(); } } }
public void start() { IMessagingBus bus = MQFactory.Instance.createMessagingBus(); try { Console.WriteLine("Creating connector"); clientConnection = bus.connect(new Uri("bnmq://127.0.0.1:3333")); clientConnection.addListener(new MQConnectionListener(this)); clientConnection.start(); //doSubscribe(); Console.WriteLine("Please enter to exit"); Console.ReadKey(); //System.in.read(); Console.WriteLine("Trying to stop example queue dispatcher"); } catch (Exception e) { Console.WriteLine(e.ToString()); } finally { if (queue != null) { Console.WriteLine("Trying to stop receiveing from remote queue"); queue.stop(); } if (clientConnection != null) { Console.WriteLine("Trying to close connector"); clientConnection.close(); } if (bus != null) { Console.WriteLine("Trying to finallize messaging bus"); bus.close(); } } }
public void Close() { if (bus != null) { bus.close(); bus = null; } if (talkerConnection != null) { talkerConnection.close(); // not sure why this locks up talkerConnection = null; } if (talkerConnectionListener != null) { talkerConnectionListener.Close(); talkerConnectionListener = null; } if (ptpTalkerSession != null) { ptpTalkerSession.close(); ptpTalkerSession = null; } }
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(); } } }
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(); } } }