Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            var endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5467);
            var parser   = new StompParser();

            using (var reStompService = new StompService(endPoint, parser))
            {
                reStompService.Start((middlewareStack) =>
                {
                    middlewareStack.Push(new TerminationMiddleware().Invoke);
                    middlewareStack.Push(new ProtocolVersionMiddleware().Invoke);
                    middlewareStack.Push(new SessionMiddleware().Invoke);
                    middlewareStack.Push(new SendMiddleware().Invoke);
                });

                Console.WriteLine("Service started.");

                var client = new StompClient();

                var session = client.Connect("127.0.0.1", 5467).Result;

                if (session != null)
                {
                    client.Send(new Dictionary <string, string> {
                        ["receipt-id"] = "111"
                    }, "WOO!").Wait();
                }

                Console.ReadLine();
            }
        }
Exemplo n.º 2
0
        private static void WaitForSubscriptionConformation(StompClient client, string queue)
        {
            var subscribed             = false;
            var retryCount             = 20;
            var message                = "connected to:" + queue;
            var originalMessageHandler = client.OnMessage;

            client.OnMessage = null;
            client.OnMessage = msg => subscribed = msg.Body == message;

            while (!subscribed && retryCount > 0)
            {
                client.Send(queue, message);

                Thread.Sleep(1500);
                retryCount--;
            }

            client.OnMessage = originalMessageHandler;

            if (retryCount == 0)
            {
                throw new InvalidOperationException("Timeout waiting for stomp broker to respond");
            }
        }
Exemplo n.º 3
0
        public void send_must_include_a_frame()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();

            var    sut    = new StompClient(channel, transactionManager);
            Action actual = () => sut.Send(null);

            actual.ShouldThrow <ArgumentNullException>();
        }
Exemplo n.º 4
0
        public void send_message_directly()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();
            var frame = new BasicFrame("SEND");

            var sut = new StompClient(channel, transactionManager);

            sut.Send(frame);

            channel.Received().Send(frame);
        }
Exemplo n.º 5
0
        public void server_should_receive_messages_send_by_client()
        {
            Assert.That(_server.Queues, Is.Empty);

            _client1.Send("123", "foo:bar");

            Thread.Sleep(TimeSpan.FromSeconds(3));

            var stompQueue = _server.Queues.First();
            var store      = stompQueue.Store;

            Assert.That(store.HasMessages(), Is.True);
            string msg;

            store.TryDequeue(out msg);
            Assert.That(msg, Is.EqualTo("foo:bar"));
        }
Exemplo n.º 6
0
        public void TestMessageHandlerIsWrappedCorrectl()
        {
            WebSocketPath path = new WebSocketPath("ws", "localhost", 6601, "Test");

            client            = StompClient.Over(path, null);
            client.OnMessage += onMessage;
            Dictionary <string, string> headers = new Dictionary <string, string> ();

            headers.Add(StompHeaders.DESTINATION, "/test");
            headers.Add(StompHeaders.ID, "id");
            client.Open();
            client.Send(new SendFrame("Hello world", headers));

            while (!messageArrived)
            {
                // Wait for event to arrive, then quit.
            }

            Assert.AreEqual(StompCommands.MESSAGE, message.Command);
            StringAssert.AreEqualIgnoringCase("Hello world\0", message.Body);
            StringAssert.AreEqualIgnoringCase("/test", message.Headers [StompHeaders.DESTINATION]);
            StringAssert.AreEqualIgnoringCase("1", message.Headers [StompHeaders.MESSAGE_ID]);
            client.Close();
        }
Exemplo n.º 7
0
        private static void Main(string[] args)
        {
            const string address    = "ws://localhost:8181/";
            var          wsListener = new StompWebsocketListener(address);

            wsListener.OnConnect
                += stompClient =>
                {
                Console.WriteLine("a new client connected!");
                stompClient.OnMessage += msg => Console.Out.WriteLine("msg received: {0} {1}", msg.Command, msg.Body);
                };

            var server = new StompServer(wsListener);

            server.Start();

            var client = new StompClient(new WebTransportTransport(address));

            client.Connect();
            client.Send("/queue/test", "hi there. you are the first to connect");

            Console.Out.WriteLine("Press [Enter] to stop the server");
            Console.ReadLine();
        }
Exemplo n.º 8
0
 /// <summary>
 /// Sends the message to the specified destination.
 /// </summary>
 /// <param name="destination">The destination.</param>
 /// <param name="message">The message.</param>
 public void Send(string destination, string message)
 {
     _stompClient.Send(destination, message);
 }
Exemplo n.º 9
0
 private void btnSend_Click(object sender, EventArgs e)
 {
     client.Send(toSend);
 }