private async Task AssertMessagePublishedAndReceivedAsync <T>(
            IServiceCollection services,
            IHandlerAsync <T> handler,
            TaskCompletionSource <object> completionSource)
            where T : Message, new()
        {
            IServiceProvider serviceProvider = services.BuildServiceProvider();

            IMessagePublisher publisher = serviceProvider.GetRequiredService <IMessagePublisher>();
            IMessagingBus     listener  = serviceProvider.GetRequiredService <IMessagingBus>();

            using var source = new CancellationTokenSource(Timeout);
            await listener.StartAsync(source.Token);

            await publisher.StartAsync(source.Token);


            var message = new T();

            // Act
            await publisher.PublishAsync(message, source.Token);

            // Assert
            try
            {
                completionSource.Task.Wait(source.Token);
            }
            catch (OperationCanceledException)
            {
                // Ignore
            }

            await handler.Received(1).Handle(Arg.Is <T>((p) => p.UniqueKey() == message.UniqueKey()));
        }
예제 #2
0
        public TalkerSession(SessionTypeEnum sessionType, string busAddress)
        {
            topLevelTreeNode = null;
            bus = MQFactory.Instance.createMessagingBus();
            if (sessionType == SessionTypeEnum.Server)
            {
                talkerConnection = bus.create(new Uri(busAddress));
                ptpTalkerSession = talkerConnection.createPTPSession <T>("serverPTP", "ptpSimpleSession");
            }
            else if (sessionType == SessionTypeEnum.Client)
            {
                talkerConnection = bus.connect(new Uri(busAddress));
                ptpTalkerSession = talkerConnection.createPTPSession <T>("clientPTP", "ptpSimpleSession");
            }
            else
            {
                throw new Exception("Session Type must be either Server or Client");
            }
            this.sessionType = sessionType;

            talkerConnectionListener = new TalkerConnectionListener();
            talkerConnection.addListener(talkerConnectionListener);
            ptpTalkerSession.addListener(this);

            talkerConnection.start();
        }
예제 #3
0
        private async Task AssertMessagePublishedAndReceivedAsync <T>(
            IServiceCollection services,
            IHandlerAsync <T> handler,
            TaskCompletionSource <object> completionSource)
            where T : Message
        {
            IServiceProvider serviceProvider = services.BuildServiceProvider();

            IMessagePublisher publisher = serviceProvider.GetRequiredService <IMessagePublisher>();
            IMessagingBus     listener  = serviceProvider.GetRequiredService <IMessagingBus>();

            using (var source = new CancellationTokenSource(Timeout))
            {
                listener.Start(source.Token);

                var message = new SimpleMessage();

                // Act
                await publisher.PublishAsync(message, source.Token);

                // Assert
                completionSource.Task.Wait(source.Token);

                await handler.Received(1).Handle(Arg.Any <T>());
            }
        }
 public DataImportApplicationService(IMessagingBus messagingBus,
                                     IFileManagementApplicationService fileManagementApplicationService,
                                     IConfiguration configration)
 {
     _messagingBus = messagingBus;
     _fileManagementApplicationService = fileManagementApplicationService;
     _configuration = configration;
 }
예제 #5
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();
                }
            }
        }
예제 #6
0
        protected async Task WhenAsync(IServiceCollection services, Func <IMessagePublisher, IMessagingBus, IServiceProvider, CancellationToken, Task> action)
        {
            IServiceProvider serviceProvider = services.BuildServiceProvider();

            IMessagePublisher publisher = serviceProvider.GetRequiredService <IMessagePublisher>();
            IMessagingBus     listener  = serviceProvider.GetRequiredService <IMessagingBus>();

            await RunActionWithTimeout(async cancellationToken =>
                                       await action(publisher, listener, serviceProvider, cancellationToken)
                                       .ConfigureAwait(false));
        }
예제 #7
0
        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();
                }
            }
        }
예제 #8
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();
                }
            }
        }
예제 #9
0
        public async Task Can_Create_Messaging_Bus_Fluently_For_A_Queue()
        {
            // Arrange
            var completionSource = new TaskCompletionSource <object>();
            var handler          = Substitute.For <IHandlerAsync <SimpleMessage> >();

            handler.Handle(Arg.Any <SimpleMessage>())
            .Returns(true)
            .AndDoes((_) => completionSource.SetResult(null));

            using var container = new Container(
                      (registry) =>
            {
                registry.For <ILoggerFactory>()
                .Use(() => OutputHelper.ToLoggerFactory())
                .Singleton();

                registry.For <IHandlerAsync <SimpleMessage> >()
                .Use(handler);

                registry.AddJustSaying(
                    (builder) =>
                {
                    builder.Client((options) =>
                                   options.WithBasicCredentials("accessKey", "secretKey")
                                   .WithServiceUri(TestEnvironment.SimulatorUrl))
                    .Messaging((options) => options.WithRegions("eu-west-1"))
                    .Publications((options) => options.WithQueue <SimpleMessage>())
                    .Subscriptions((options) => options.ForQueue <SimpleMessage>());
                });
            });

            IMessagePublisher publisher = container.GetInstance <IMessagePublisher>();
            IMessagingBus     listener  = container.GetInstance <IMessagingBus>();

            var message = new SimpleMessage();

            using var source = new CancellationTokenSource(TimeSpan.FromSeconds(20));
            await listener.StartAsync(source.Token);

            await publisher.StartAsync(source.Token);

            // Act
            await publisher.PublishAsync(message, source.Token);

            completionSource.Task.Wait(source.Token);

            // Assert
            await handler.Received().Handle(Arg.Any <SimpleMessage>());
        }
예제 #10
0
    public async Task Can_Create_Messaging_Bus_Fluently_For_A_Queue()
    {
        // Arrange
        var handler = new InspectableHandler <SimpleMessage>();

        using var container = new Container(
                  (registry) =>
        {
            registry.For <ILoggerFactory>()
            .Use(() => OutputHelper.ToLoggerFactory())
            .Singleton();

            registry.For <IHandlerAsync <SimpleMessage> >()
            .Use(handler);

            registry.AddJustSaying(
                (builder) =>
            {
                builder.Client((options) =>
                               options.WithBasicCredentials("accessKey", "secretKey")
                               .WithServiceUri(TestEnvironment.SimulatorUrl))
                .Messaging((options) => options.WithRegion("eu-west-1"))
                .Publications((options) => options.WithQueue <SimpleMessage>())
                .Subscriptions((options) => options.ForQueue <SimpleMessage>());
            });
        });

        IMessagePublisher publisher = container.GetInstance <IMessagePublisher>();
        IMessagingBus     listener  = container.GetInstance <IMessagingBus>();

        var message = new SimpleMessage();

        using var source = new CancellationTokenSource(TimeSpan.FromSeconds(20));
        await listener.StartAsync(source.Token);

        await publisher.StartAsync(source.Token);

        // Act
        await publisher.PublishAsync(message, source.Token);

        await Patiently.AssertThatAsync(OutputHelper,
                                        () => handler.ReceivedMessages.Any());

        // Assert
        handler.ReceivedMessages.ShouldContain(x => x.GetType() == typeof(SimpleMessage));
    }
        public void Can_Create_Messaging_Bus()
        {
            // Arrange
            var services = new ServiceCollection()
                           .AddLogging((p) => p.AddXUnit(OutputHelper))
                           .AddJustSaying("eu-west-1")
                           .AddJustSayingHandler <QueueMessage, QueueHandler>();

            IServiceProvider serviceProvider = services.BuildServiceProvider();

            IMessagePublisher publisher = serviceProvider.GetRequiredService <IMessagePublisher>();
            IMessagingBus     listener  = serviceProvider.GetRequiredService <IMessagingBus>();

            using (var source = new CancellationTokenSource(TimeSpan.FromSeconds(20)))
            {
                // Act
                listener.StartAsync(source.Token);
            }
        }
예제 #12
0
        public async Task Can_Create_Messaging_Bus_Fluently_For_A_Topic()
        {
            var topicName = Guid.NewGuid().ToString();

            // Arrange
            var services = new ServiceCollection()
                           .AddLogging((p) => p.AddXUnit(OutputHelper))
                           .AddJustSaying(
                (builder) =>
            {
                builder
                .Client((options) =>
                        options.WithBasicCredentials("accessKey", "secretKey")
                        .WithServiceUri(TestEnvironment.SimulatorUrl))
                .Messaging((options) => options.WithRegion("eu-west-1"))
                .Publications((options) => options.WithTopic <TopicMessage>())
                .Subscriptions((options) => options.ForTopic <TopicMessage>(cfg => cfg.WithName(topicName)));
            })
                           .AddSingleton <IMessageStore <TopicMessage>, TestMessageStore <TopicMessage> >()
                           .AddJustSayingHandler <TopicMessage, MessageStoringHandler <TopicMessage> >();

            IServiceProvider serviceProvider = services.BuildServiceProvider();

            IMessagePublisher publisher = serviceProvider.GetRequiredService <IMessagePublisher>();
            IMessagingBus     listener  = serviceProvider.GetRequiredService <IMessagingBus>();

            using (var source = new CancellationTokenSource(TimeSpan.FromSeconds(20)))
            {
                // Act
                await listener.StartAsync(source.Token);

                await publisher.StartAsync(source.Token);

                var message = new TopicMessage();

                await publisher.PublishAsync(message, source.Token);

                var store = serviceProvider.GetService <IMessageStore <TopicMessage> >();

                await Patiently.AssertThatAsync(OutputHelper,
                                                () => store.Messages.Any(msg => msg.Id == message.Id));
            }
        }
        public async Task Can_Create_Messaging_Bus_Fluently_For_A_Topic()
        {
            // Arrange
            var services = new ServiceCollection()
                           .AddLogging((p) => p.AddXUnit(OutputHelper))
                           .AddJustSaying(
                (builder) =>
            {
                builder
                .Client((options) =>
                        options.WithBasicCredentials("accessKey", "secretKey")
                        .WithServiceUri(TestEnvironment.SimulatorUrl))
                .Messaging((options) => options.WithRegions("eu-west-1"))
                .Publications((options) => options.WithTopic <TopicMessage>())
                .Subscriptions((options) => options.ForTopic <TopicMessage>());
            })
                           .AddJustSayingHandler <TopicMessage, TopicHandler>();

            IServiceProvider serviceProvider = services.BuildServiceProvider();

            IMessagePublisher publisher = serviceProvider.GetRequiredService <IMessagePublisher>();
            IMessagingBus     listener  = serviceProvider.GetRequiredService <IMessagingBus>();

            using (var source = new CancellationTokenSource(TimeSpan.FromSeconds(20)))
            {
                // Act
                await listener.StartAsync(source.Token);

                await publisher.StartAsync(source.Token);

                var message = new TopicMessage();

                await publisher.PublishAsync(message, source.Token);

                // Assert
                while (!source.IsCancellationRequested && !TopicHandler.MessageIds.Contains(message.Id))
                {
                    await Task.Delay(TimeSpan.FromSeconds(0.2), source.Token);
                }

                TopicHandler.MessageIds.ShouldContain(message.Id);
            }
        }
예제 #14
0
        public async Task Can_Create_Messaging_Bus_With_Contributors()
        {
            // Arrange
            var services = new ServiceCollection()
                           .AddLogging((p) => p.AddXUnit(OutputHelper))
                           .AddJustSaying()
                           .AddSingleton <IMessageBusConfigurationContributor, AwsContributor>()
                           .AddSingleton <IMessageBusConfigurationContributor, MessagingContributor>()
                           .AddSingleton <IMessageBusConfigurationContributor, QueueContributor>()
                           .AddSingleton <IMessageBusConfigurationContributor, RegionContributor>()
                           .AddJustSayingHandler <QueueMessage, MessageStoringHandler <QueueMessage> >()
                           .AddSingleton <IMessageStore <QueueMessage>, TestMessageStore <QueueMessage> >()
                           .AddSingleton <MyMonitor>();

            IServiceProvider serviceProvider = services.BuildServiceProvider();

            IMessagePublisher publisher = serviceProvider.GetRequiredService <IMessagePublisher>();
            IMessagingBus     listener  = serviceProvider.GetRequiredService <IMessagingBus>();

            using (var source = new CancellationTokenSource(TimeSpan.FromSeconds(20)))
            {
                // Act
                await listener.StartAsync(source.Token);

                await publisher.StartAsync(source.Token);

                var message = new QueueMessage();

                await publisher.PublishAsync(message, source.Token);

                // Assert
                var messageStore = serviceProvider.GetService <IMessageStore <QueueMessage> >();

                await Patiently.AssertThatAsync(OutputHelper,
                                                () =>
                {
                    messageStore.Messages.ShouldContain(msg =>
                                                        msg.Id.Equals(message.Id));
                });
            }
        }
        public async Task Can_Create_Messaging_Bus_With_Contributors()
        {
            // Arrange
            var services = new ServiceCollection()
                           .AddLogging((p) => p.AddXUnit(OutputHelper))
                           .AddJustSaying()
                           .AddSingleton <IMessageBusConfigurationContributor, AwsContributor>()
                           .AddSingleton <IMessageBusConfigurationContributor, MessagingContributor>()
                           .AddSingleton <IMessageBusConfigurationContributor, QueueContributor>()
                           .AddSingleton <IMessageBusConfigurationContributor, RegionContributor>()
                           .AddJustSayingHandler <QueueMessage, QueueHandler>()
                           .AddSingleton <MyMonitor>();

            IServiceProvider serviceProvider = services.BuildServiceProvider();

            IMessagePublisher publisher = serviceProvider.GetRequiredService <IMessagePublisher>();
            IMessagingBus     listener  = serviceProvider.GetRequiredService <IMessagingBus>();

            using (var source = new CancellationTokenSource(TimeSpan.FromSeconds(20)))
            {
                // Act
                await listener.StartAsync(source.Token);

                await publisher.StartAsync(source.Token);

                var message = new QueueMessage();

                await publisher.PublishAsync(message, source.Token);

                // Assert
                while (!source.IsCancellationRequested && !QueueHandler.MessageIds.Contains(message.Id))
                {
                    await Task.Delay(TimeSpan.FromSeconds(0.2), source.Token);
                }

                QueueHandler.MessageIds.ShouldContain(message.Id);
            }
        }
예제 #16
0
        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();
                }
            }
        }
예제 #17
0
 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;
     }
 }
예제 #18
0
 public Subscriber(IMessagingBus bus, ILogger <Subscriber> logger)
 {
     _bus    = bus;
     _logger = logger;
 }
예제 #19
0
 public Subscriber(IMessagingBus bus, ILogger <Subscriber> logger, IMessagePublisher publisher)
 {
     _bus       = bus;
     _logger    = logger;
     _publisher = publisher;
 }
예제 #20
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();
                }
            }
        }
예제 #21
0
 public BusService(IMessagingBus bus, ILogger <BusService> logger, IMessagePublisher publisher)
 {
     _bus       = bus;
     _logger    = logger;
     _publisher = publisher;
 }
예제 #22
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();
                }
            }
        }
예제 #23
0
 public BusService(IMessagingBus bus, ILogger <BusService> logger)
 {
     _bus    = bus;
     _logger = logger;
 }