Esempio n. 1
0
        public void IntegrationHappyPath()
        {
            var numberOfMessagesToSend   = 1000;
            var numberOfReceivedMessages = 0;
            var consumer1 = MessagingScenarioFactory.CreateQueueConsumer("test1");

            consumer1.MessageReceived += delegate(object sender, MessageReceivedEventArgs args)
            {
                numberOfReceivedMessages++;
                Console.WriteLine("1: " + args.Message.GetStringValue());
            };
            var consumer2 = MessagingScenarioFactory.CreateQueueConsumer("test1");

            consumer2.MessageReceived += delegate(object sender, MessageReceivedEventArgs args)
            {
                numberOfReceivedMessages++;
                Thread.Sleep(100);
                Console.WriteLine("2: " + args.Message.GetStringValue());
            };
            consumer2.Start();
            consumer1.Start();

            var producer = MessagingScenarioFactory.CreateQueueProducer("test1");

            for (int j = 0; j < numberOfMessagesToSend; j++)
            {
                producer.Send(j.ToString());
            }
            Thread.Sleep(10000);

            Assert.That(numberOfReceivedMessages, Is.EqualTo(numberOfMessagesToSend), numberOfReceivedMessages.ToString());
        }
Esempio n. 2
0
        private static void SendAndReceiveOneMessage()
        {
            // Use a wait handle to pause the main thread while waiting for the message to be received.
            var waitHandle = new AutoResetEvent(false);

            var namedPipeProducer = MessagingScenarioFactory.CreateQueueProducer("Pipe1");
            var namedPipeConsumer = MessagingScenarioFactory.CreateQueueConsumer("Pipe1");

            namedPipeConsumer.MessageReceived += (sender, eventArgs) =>
            {
                var eventArgsMessage = eventArgs.Message;
                var message          = eventArgsMessage.GetStringValue();

                Console.WriteLine($"Message received: {message}");

                waitHandle.Set();
            };
            namedPipeConsumer.Start();

            namedPipeProducer.Send($"Named pipe test message from {typeof(Program).FullName}");

            waitHandle.WaitOne();

            namedPipeConsumer.Dispose();
            namedPipeProducer.Dispose();
            waitHandle.Dispose();

            Console.Write("Press any key to exit...");
            Console.ReadKey(true);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // The AWS credentials should be provide via a profile or other more secure means. This is only for example.
            // See http://http://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-config-creds.html
            var options = new CredentialProfileOptions
            {
                AccessKey = "AKIAJWXCD7ZCUGRQYCMA",
                SecretKey = "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"
            };
            var profile = new CredentialProfile("default", options)
            {
                Region = RegionEndpoint.USWest2
            };

            new NetSDKCredentialsFile().RegisterProfile(profile);

            var producer = MessagingScenarioFactory.CreateQueueProducer("queue");
            var consumer = MessagingScenarioFactory.CreateQueueConsumer("queue");

            consumer.Start();
            consumer.MessageReceived += (sender, eventArgs) =>
            {
                var eventArgsMessage = eventArgs.Message;
                var message          = eventArgsMessage.GetStringValue();

                Console.WriteLine($"Message: {message}");
            };

            producer.Send("Test SQS Message!");
        }
Esempio n. 4
0
        public void MessagingScenarioFactoryPassThroughOnCreateQueueProducer()
        {
            var mockReceiver = new Mock <ISender>();
            var mockFactory  = new Mock <IMessagingScenarioFactory>();

            mockFactory.Setup(mf => mf.CreateQueueProducer(It.IsAny <string>())).Returns(mockReceiver.Object);

            ResetFactory();
            MessagingScenarioFactory.SetCurrent(mockFactory.Object);

            MessagingScenarioFactory.CreateQueueProducer("test").Should().BeSameAs(mockReceiver.Object);
        }
Esempio n. 5
0
 private static void RunSender()
 {
     using (var sender = MessagingScenarioFactory.CreateQueueProducer("Pipe1"))
     {
         Console.WriteLine($"Enter a message for sender '{sender.Name}'. Leave blank to quit.");
         string message;
         while (true)
         {
             Console.Write("message>");
             if ((message = Console.ReadLine()) == "")
             {
                 return;
             }
             sender.Send(message);
         }
     }
 }
Esempio n. 6
0
        public void MinimalistConfigsShouldBehaveAsExpected()
        {
            var  consumer  = MessagingScenarioFactory.CreateQueueConsumer("validReceiver");
            bool roundTrip = false;

            consumer.MessageReceived += (sender, args) => roundTrip = true;
            consumer.Start();
            var producer = MessagingScenarioFactory.CreateQueueProducer("validSender");

            for (int i = 0; i < 10; i++)
            {
                producer.Send("TestMessagePleaseIgnore");
            }

            Thread.Sleep(100);

            Assert.That(roundTrip);
        }
Esempio n. 7
0
        // using project reference for now, will change to nuget once we get Messaging Stable
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var namedPipeProducer = MessagingScenarioFactory.CreateQueueProducer("NampedPipeTester");
            var namedPipeConsumer = MessagingScenarioFactory.CreateQueueConsumer("NampedPipeTester");

            namedPipeConsumer.Start();
            namedPipeConsumer.MessageReceived += (sender, eventArgs) =>
            {
                var eventArgsMessage = eventArgs.Message;
                var message          = eventArgsMessage.GetStringValue();

                Console.WriteLine($"Message: {message}");
            };

            namedPipeProducer.Send("Test Named Pipe Message");
        }