Ejemplo n.º 1
0
        public void Can_get_message_from_client_connection()
        {
            using (var connection = new RavenMQConnection(new Uri(configuration.ServerUrl)))
            {
                var             manualResetEventSlim = new ManualResetEventSlim(false);
                OutgoingMessage msg = null;
                connection.SubscribeRaw("/queues/abc", (context, message) =>
                {
                    msg = message;
                    manualResetEventSlim.Set();
                });

                WaitForSubscription();

                ravenMqServer.Queues.Enqueue(new IncomingMessage
                {
                    Data  = new byte[] { 1, 2, 3 },
                    Queue = "/queues/abc"
                });

                manualResetEventSlim.Wait();

                Assert.Equal(new byte[] { 1, 2, 3 }, msg.Data);
            }
        }
Ejemplo n.º 2
0
        public void Can_send_a_message_from_receiving_msg()
        {
            using (var connection = new RavenMQConnection(new Uri(configuration.ServerUrl)))
            {
                var             manualResetEventSlim = new ManualResetEventSlim(false);
                OutgoingMessage msg = null;
                connection.SubscribeRaw("/queues/abc", (context, message) =>
                {
                    msg = message;
                    context.Send(new IncomingMessage
                    {
                        Data  = new byte[] { 4, 5, 6 },
                        Queue = "/queues/def"
                    });
                    manualResetEventSlim.Set();
                });

                WaitForSubscription();

                ravenMqServer.Queues.Enqueue(new IncomingMessage
                {
                    Data  = new byte[] { 1, 2, 3 },
                    Queue = "/queues/abc"
                });

                manualResetEventSlim.Wait();

                Assert.Equal(new byte[] { 1, 2, 3 }, msg.Data);

                ReadResults results;
                do
                {
                    results = ravenMqServer.Queues.Read(new ReadRequest
                    {
                        Queue = "/queues/def"
                    });
                    Thread.Sleep(1);
                } while (results.Results.Count() == 0);

                Assert.Equal(new byte[] { 4, 5, 6 }, results.Results.First().Data);
            }
        }
Ejemplo n.º 3
0
        public void Publishing_from_the_client_out_of_scope()
        {
            using (var connection = new RavenMQConnection(new Uri(configuration.ServerUrl)))
            {
                connection.StartPublishing.AddRaw(new IncomingMessage
                {
                    Queue = "/queues/abc",
                    Data  = new byte[] { 1, 2, 3 },
                }).PublishAsync();
                var             manualResetEventSlim = new ManualResetEventSlim(false);
                OutgoingMessage msg = null;
                connection.SubscribeRaw("/queues/abc", (context, message) =>
                {
                    msg = message;
                    manualResetEventSlim.Set();
                });

                manualResetEventSlim.Wait(TimeSpan.FromSeconds(10));

                Assert.Equal(new byte[] { 1, 2, 3 }, msg.Data);
            }
        }
Ejemplo n.º 4
0
        public void Can_flush_messages_manually()
        {
            using (var connection = new RavenMQConnection(new Uri(configuration.ServerUrl)))
            {
                connection.ConnectToServerTask.Wait();
                var             manualResetEventSlim = new ManualResetEventSlim(false);
                OutgoingMessage msg = null;
                connection.SubscribeRaw("/queues/abc", (context, message) =>
                {
                    msg = message;
                    context.Send(new IncomingMessage
                    {
                        Data  = new byte[] { 4, 5, 6 },
                        Queue = "/queues/def"
                    });
                    context.FlushAsync().Wait();
                    manualResetEventSlim.Set();
                });

                WaitForSubscription();

                ravenMqServer.Queues.Enqueue(new IncomingMessage
                {
                    Data  = new byte[] { 1, 2, 3 },
                    Queue = "/queues/abc"
                });

                manualResetEventSlim.Wait();

                Assert.Equal(new byte[] { 1, 2, 3 }, msg.Data);

                var results = ravenMqServer.Queues.Read(new ReadRequest
                {
                    Queue = "/queues/def"
                });

                Assert.Equal(new byte[] { 4, 5, 6 }, results.Results.First().Data);
            }
        }
Ejemplo n.º 5
0
        public void Can_flush_messages_manually()
        {
            using (var connection = new RavenMQConnection(new Uri(configuration.ServerUrl)))
            {
                connection.ConnectToServerTask.Wait();
                var manualResetEventSlim = new ManualResetEventSlim(false);
                OutgoingMessage msg = null;
                connection.SubscribeRaw("/queues/abc", (context, message) =>
                {
                    msg = message;
                    context.Send(new IncomingMessage
                    {
                        Data = new byte[] { 4, 5, 6 },
                        Queue = "/queues/def"
                    });
                    context.FlushAsync().Wait();
                    manualResetEventSlim.Set();
                });

                WaitForSubscription();

                ravenMqServer.Queues.Enqueue(new IncomingMessage
                {
                    Data = new byte[] { 1, 2, 3 },
                    Queue = "/queues/abc"
                });

                manualResetEventSlim.Wait();

                Assert.Equal(new byte[] { 1, 2, 3 }, msg.Data);

                var results = ravenMqServer.Queues.Read(new ReadRequest
                {
                    Queue = "/queues/def"
                });

                Assert.Equal(new byte[] { 4, 5, 6 }, results.Results.First().Data);
            }
        }
Ejemplo n.º 6
0
        public void Can_get_message_from_client_connection()
        {
            using(var connection = new RavenMQConnection(new Uri(configuration.ServerUrl)))
            {
                var manualResetEventSlim = new ManualResetEventSlim(false);
                OutgoingMessage msg = null;
                connection.SubscribeRaw("/queues/abc", (context, message) =>
                {
                    msg = message;
                    manualResetEventSlim.Set();
                });

                WaitForSubscription();

                ravenMqServer.Queues.Enqueue(new IncomingMessage
                {
                    Data = new byte[] {1, 2, 3},
                    Queue = "/queues/abc"
                });

                manualResetEventSlim.Wait();

                Assert.Equal(new byte[]{1,2,3}, msg.Data);
            }
        }
Ejemplo n.º 7
0
        public void Publishing_from_the_client_out_of_scope()
        {
            using (var connection = new RavenMQConnection(new Uri(configuration.ServerUrl)))
            {

                connection.StartPublishing.AddRaw(new IncomingMessage
                {
                    Queue = "/queues/abc",
                    Data = new byte[] {1, 2, 3},
                }).PublishAsync();
                var manualResetEventSlim = new ManualResetEventSlim(false);
                OutgoingMessage msg = null;
                connection.SubscribeRaw("/queues/abc", (context, message) =>
                {
                    msg = message;
                    manualResetEventSlim.Set();
                });

                manualResetEventSlim.Wait(TimeSpan.FromSeconds(10));

                Assert.Equal(new byte[] { 1, 2, 3 }, msg.Data);
            }
        }
Ejemplo n.º 8
0
        public void Can_send_a_message_from_receiving_msg()
        {
            using (var connection = new RavenMQConnection(new Uri(configuration.ServerUrl)))
            {
                var manualResetEventSlim = new ManualResetEventSlim(false);
                OutgoingMessage msg = null;
                connection.SubscribeRaw("/queues/abc", (context, message) =>
                {
                    msg = message;
                    context.Send(new IncomingMessage
                    {
                        Data = new byte[] {4, 5, 6},
                        Queue = "/queues/def"
                    });
                    manualResetEventSlim.Set();
                });

                WaitForSubscription();

                ravenMqServer.Queues.Enqueue(new IncomingMessage
                {
                    Data = new byte[] { 1, 2, 3 },
                    Queue = "/queues/abc"
                });

                manualResetEventSlim.Wait();

                Assert.Equal(new byte[] { 1, 2, 3 }, msg.Data);

                ReadResults results;
                do
                {
                    results = ravenMqServer.Queues.Read(new ReadRequest
                    {
                        Queue = "/queues/def"
                    });
                    Thread.Sleep(1);
                } while (results.Results.Count() == 0);

                Assert.Equal(new byte[]{4,5,6}, results.Results.First().Data);
            }
        }