示例#1
0
        public void ack_messages_can_ack_all_since_we_dont_allow_multiple_pending_messages_with_client_individual_ack_type()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();
            var client             = Substitute.For <IStompClient>();
            var subscription       = new Subscription(client, "abc");

            subscription.AckType = "client";
            var frame1 = new BasicFrame("MESSAGE");

            frame1.AddHeader("message-id", "kdkd1");
            var frame2 = new BasicFrame("MESSAGE");

            frame2.AddHeader("message-id", "kdkd2");
            var frame3 = new BasicFrame("MESSAGE");

            frame3.AddHeader("message-id", "kdkd3");
            subscription.Send(frame1);
            subscription.Send(frame2);
            subscription.Send(frame3);

            var sut = new StompClient(channel, transactionManager);

            sut.AddSubscription(subscription);
            sut.AckMessages("kdkd2");
            var actual1 = sut.IsFramePending("kdkd1");
            var actual2 = sut.IsFramePending("kdkd2");
            var actual3 = sut.IsFramePending("kdkd3");

            actual1.Should().BeFalse();
            actual2.Should().BeFalse();
            actual3.Should().BeTrue();
        }
示例#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");
            }
        }
示例#3
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();
            }
        }
示例#4
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="StompConnection" /> class.
        /// </summary>
        /// <param name="stompClient"> The stomp client. </param>
        public StompConnection(StompClient stompClient)
        {
            Messages = new ConcurrentQueue <StompMessage>();

            _stompClient            = stompClient;
            _stompClient.OnMessage += m => Messages.Enqueue(m);
        }
示例#5
0
 public void InitializeService()
 {
     this.client = new StompClient(this.configuration);
     this.client.throwMessage += new StompClient.MessageEvent(this.throwMessage);
     try
     {
         this.throwMessage("Connecting to Silicondash...");
         bool flag = this.client.Connect();
         if (!flag)
         {
             this.throwMessage("Connect to Silicondash failed.");
         }
         else
         {
             Thread.Sleep(0x3e8);
             flag = this.client.Subscribe();
         }
         if (!flag)
         {
             this.throwMessage("Subscribe failed.");
         }
         else
         {
             Thread.Sleep(0x3e8);
             this.client.StartService();
             this.throwMessage("Start listening...");
         }
     }
     catch (Exception exception)
     {
         this.throwMessage(string.Format("Connnecting to {0} Silicondash failed, {1}", this.configuration.OSATID, exception.Message));
     }
 }
示例#6
0
 public void connect()
 {
     stompClient = new StompClientAll("ws://127.0.0.1:8080/gs-guide-websocket");
     stompClient.StompConnect().add(() => {
         Debug.Log("Connected!!!");
         stompClient.Subscribe("/topic/greetings", onMsg);
     });
 }
示例#7
0
 public Form1()
 {
     InitializeComponent();
     client             = new StompClient("127.0.0.1", 12345);
     client.OnReceived += Client_OnReceived;
     toSend             = new StompMessage();
     connected          = false;
 }
示例#8
0
        public void Setup()
        {
            var inMemoryListener = new StompInMemoryListener();
            _server = new StompServer(inMemoryListener);
            _client1 = new StompClient(new InMemoryTransport(inMemoryListener));

            _server.Start();
            _client1.Connect();
        }
示例#9
0
        public void is_for_Channel_doesnt_work_for_unknown_Channel()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();

            var sut    = new StompClient(channel, transactionManager);
            var actual = sut.IsForChannel(Substitute.For <ITcpChannel>());

            actual.Should().BeFalse();
        }
示例#10
0
        public void is_for_Channel_checks_internal_channel_object()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();

            var sut    = new StompClient(channel, transactionManager);
            var actual = sut.IsForChannel(channel);

            actual.Should().BeTrue();
        }
示例#11
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>();
        }
示例#12
0
        public void Setup()
        {
            const string pipeName = "ws://localhost:8080/";

            _server = new StompServer(new StompWebsocketListener(pipeName));
            _client = new StompClient(new WebTransportTransport(pipeName));

            _server.Start();
            _client.Connect();
        }
示例#13
0
        public void Setup()
        {
            var inMemoryListener = new StompInMemoryListener();

            _server  = new StompServer(inMemoryListener);
            _client1 = new StompClient(new InMemoryTransport(inMemoryListener));

            _server.Start();
            _client1.Connect();
        }
示例#14
0
        public void cant_get_non_existent_subscription()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();

            var    sut    = new StompClient(channel, transactionManager);
            Action actual = () => sut.GetSubscription("abc");

            actual.ShouldThrow <NotFoundException>();
        }
示例#15
0
        public void Setup()
        {
            const string pipeName = "ws://localhost:8080/";

            _server = new StompServer(new StompWebsocketListener(pipeName));
            _client = new StompClient(new WebTransportTransport(pipeName));

            _server.Start();
            _client.Connect();
        }
示例#16
0
        public void cleanup_cleans_transactions_too()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();

            var sut = new StompClient(channel, transactionManager);

            sut.Cleanup();

            transactionManager.Received().Cleanup();
        }
示例#17
0
        public void ack_unknown_message_is_an_error()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();
            var client             = Substitute.For <IStompClient>();

            var    sut    = new StompClient(channel, transactionManager);
            Action actual = () => sut.AckMessages("ksksks");

            actual.ShouldThrow <NotFoundException>();
        }
示例#18
0
        public StompChannel(StompConfig configuration, ClientContext context)
            : base(context)
        {
            SecucardTrace.Info(string.Format("configuration = '{0}'", configuration));
            _configuration = configuration;

            _channelId = Guid.NewGuid().ToString();
            _stomp     = new StompClient(_configuration);
            _stomp.StompClientFrameArrivedEvent += StompOnStompClientFrameArrivedEvent;
            _stomp.StompClientChangedEvent      += Stomp_StompClientChangedEvent;
        }
示例#19
0
        public void Begin_transaction_should_invoke_the_transactionManager()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();

            var sut = new StompClient(channel, transactionManager);

            sut.BeginTransaction("abc");

            transactionManager.Received().Begin("abc");
        }
示例#20
0
		public static void DisconnectImmediately(StompClient client)
		{
			Verify.ArgumentNotNull(client, "client");
			var message = new StompFrame(StompCommand.Disconnect)
			              	{
			              		Headers =
			              			{
			              				{StompHeader.NonStandard.KeepSession, "true"}
			              			}
			              	};
			client.SendRawMessage(message, false);
		}
示例#21
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);
        }
示例#22
0
        public void HasActiveTransactions_is_taken_from_the_TransactionManager()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();

            transactionManager.HasActiveTransactions.Returns(true);

            var sut    = new StompClient(channel, transactionManager);
            var actual = sut.HasActiveTransactions;

            actual.Should().BeTrue();
        }
示例#23
0
        public void RemoteEndpoint_is_taken_from_The_channel()
        {
            var channel = Substitute.For <ITcpChannel>();

            channel.RemoteEndpoint.Returns(new IPEndPoint(IPAddress.Loopback, 5));
            var transactionManager = Substitute.For <ITransactionManager>();

            var sut    = new StompClient(channel, transactionManager);
            var actual = sut.RemoteEndpoint;

            actual.Should().BeSameAs(channel.RemoteEndpoint);
        }
示例#24
0
        public void set_sessionkey_during_authentication()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();

            var sut = new StompClient(channel, transactionManager);

            sut.SetAsAuthenticated("kdfjkd");
            var actual = sut.SessionKey;

            actual.Should().Be("kdfjkd");
        }
示例#25
0
        public void Enqueue_transaction_should_invoke_the_transactionManager()
        {
            var    channel            = Substitute.For <ITcpChannel>();
            var    transactionManager = Substitute.For <ITransactionManager>();
            Action commitAction       = () => { };
            Action rollbackAction     = () => { };

            var sut = new StompClient(channel, transactionManager);

            sut.EnqueueInTransaction("abc", commitAction, rollbackAction);

            transactionManager.Received().Enqueue("abc", commitAction, rollbackAction);
        }
示例#26
0
        public void subscription_can_be_added_ok()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();
            var client             = Substitute.For <IStompClient>();
            var subscription       = new Subscription(client, "abc");

            var sut = new StompClient(channel, transactionManager);

            sut.AddSubscription(subscription);
            var actual = sut.SubscriptionExists("abc");

            actual.Should().BeTrue();
        }
示例#27
0
        public void Setup()
        {
            var inMemoryListener = new StompInMemoryListener();
            var wsListener = new StompWebsocketListener("ws://localhost:8080/");

            _server = new StompServer(inMemoryListener, wsListener);
            _client1 = new StompClient(new InMemoryTransport(inMemoryListener));
            _client2 = new StompClient(new WebTransportTransport("ws://localhost:8080/"));

            _server.Start();

            _client1.Connect();
            _client2.Connect();
        }
示例#28
0
        public void Setup()
        {
            var inMemoryListener = new StompInMemoryListener();
            var wsListener       = new StompWebsocketListener("ws://localhost:8080/");

            _server  = new StompServer(inMemoryListener, wsListener);
            _client1 = new StompClient(new InMemoryTransport(inMemoryListener));
            _client2 = new StompClient(new WebTransportTransport("ws://localhost:8080/"));

            _server.Start();

            _client1.Connect();
            _client2.Connect();
        }
        /// <summary>
        ///   Gets the connection.
        /// </summary>
        /// <param name = "address">The address.</param>
        /// <returns></returns>
        private StompClient GetConnection(IEndpointAddress address)
        {
            EnsureProtocolIsCorrect(address.Uri);

            var serverAddress = new UriBuilder("ws", address.Uri.Host, address.Uri.Port).Uri;

            return(_connectionCache
                   .Retrieve(address.Uri,
                             () =>
            {
                var client = new StompClient();
                client.Connect(serverAddress);
                return client;
            }));
        }
示例#30
0
        public void remove_subscription_should_really_remove_it()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();
            var client             = Substitute.For <IStompClient>();
            var subscription       = new Subscription(client, "abc");

            subscription.AckType = "client-individual";

            var sut = new StompClient(channel, transactionManager);

            sut.AddSubscription(subscription);
            var actual  = sut.RemoveSubscription(subscription.Id);
            var actual2 = sut.RemoveSubscription(subscription.Id);

            actual.Should().BeSameAs(subscription);
            actual2.Should().BeNull();
        }
示例#31
0
        public void get_existent_subscription()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();
            var client             = Substitute.For <IStompClient>();
            var subscription       = new Subscription(client, "abc");
            var frame = new BasicFrame("SEND");

            frame.AddHeader("message-id", "kdkd");
            subscription.AckType = "client-individual";
            subscription.Send(frame);

            var sut = new StompClient(channel, transactionManager);

            sut.AddSubscription(subscription);
            var actual = sut.GetSubscription("kdkd");

            actual.Should().BeSameAs(subscription);
        }
示例#32
0
        public void sent_message_should_be_pending_using_client_ack_type()
        {
            var channel            = Substitute.For <ITcpChannel>();
            var transactionManager = Substitute.For <ITransactionManager>();
            var client             = Substitute.For <IStompClient>();
            var subscription       = new Subscription(client, "abc");
            var frame = new BasicFrame("MESSAGE");

            frame.AddHeader("message-id", "kdkd");
            subscription.AckType = "client";
            subscription.Send(frame);

            var sut = new StompClient(channel, transactionManager);

            sut.AddSubscription(subscription);
            var actual = sut.IsFramePending("kdkd");

            actual.Should().BeTrue();
        }
示例#33
0
        /// <summary>
        /// Constructor of a connector for STOMP 1.2.
        /// </summary>
        /// <param name="inStream">Stream for incoming data from STOMP service.</param>
        /// <param name="outStream">Stream for outgoing data to STOMP service.</param>
        /// <param name="host">Virtual host to connect to STOMP service.</param>
        /// <param name="user">Username to authenticate to STOMP service.</param>
        /// <param name="password">Password to authenticate to STOMP service.</param>
        /// <param name="retryInterval">When sending messages that requires receipt confirmation,
        /// this interval specifies how much time to wait before sending the frame again if
        /// no receipt is received.</param>
        /// <param name="useRandomNumberGenerator">Flag to indicate random numbers must
        /// be used when creating sequence numbers for receipts, subscriptions and transactions</param>
        public Stomp12Connector(
            Stream inStream,
            Stream outStream,
            string host,
            string user                   = null,
            string password               = null,
            TimeSpan?retryInterval        = null,
            bool useRandomNumberGenerator = false)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }

            _cts    = new CancellationTokenSource();
            _client = new Stomp12Client(inStream, outStream, retryInterval, useRandomNumberGenerator);

            _host     = host;
            _user     = user;
            _password = password;
        }
示例#34
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();
        }
示例#35
0
		private void RemoveExistingMessages()
		{
			_client.Subscribe<SyncRequestResponse>(Configs.RabbitMQ_SyncRequestQueue, n =>
			{
				Kernel.Get<ILog>().Info(Guid.Empty, "Dead msg intercepted");
			});

			_client.Subscribe<DTOs.SyncResult>(Configs.RabbitMQ_SyncResultQueue, syn =>
			{
				Kernel.Get<ILog>().Info(Guid.Empty, "Dead msg intercepted");
			});

			Thread.Sleep(5000);

			_client.Dispose();
			//_client = null;
			_client = new StompClient(Configs.RabbitMQ_StompClient_Address);

			Connect();
		}
示例#36
0
		private Syncronizer()
		{
			_unitOfWork = new UnitOfWork();

			_client = new StompClient(Configs.RabbitMQ_StompClient_Address);
		}
示例#37
0
        static void Main(string[] args)
        {
            /*
            // Stomp connection
            TcpClient client = new TcpClient();

            client.Connect("localhost", 61613);

            Task.Factory.StartNew(() =>
            {
                var reader = new StreamReader(client.GetStream(), Encoding.ASCII);
                var messageFactory = new StreamMessageFactory(reader);
                while (true)
                {
                    Console.WriteLine(messageFactory.Create());
                }
            });

            var writer = new StreamWriter(client.GetStream(), Encoding.ASCII);
            var messageSerializer = new StreamMessageSerializer(writer);

            messageSerializer.Serialize(new MessageBuilder("CONNECT").Header("accept-version", "1.2").WithoutBody()).Wait();

            messageSerializer.Serialize(new MessageBuilder("SUBSCRIBE").Header("id", 1).Header("destination", "/queue/a").WithoutBody()).Wait();

            for (int i = 0; i < 1000; i++)
            {
                messageSerializer.Serialize(
                new MessageBuilder("SEND").Header("destination", "/queue/a")
                    .Header("receipt", "message-" + i)
                    .Header("inner-id", i)
                    .WithBody(Encoding.UTF8.GetBytes("Hello World"))).Wait();

            }
            */

            StompClient client = new StompClient("localhost", 61613);

            client.Transport.IncommingMessages.GetObservable("ERROR").Subscribe(m => Console.WriteLine("ERROR!" + m));
            var destination = client.GetDestination("/queue/a", client.SubscriptionBehaviors.AutoAcknowledge);
            
            IReceiptBehavior receiptBehavior = new ReceiptBehavior(destination.Destination, client.Transport.IncommingMessages);
            receiptBehavior = NoReceiptBehavior.Default;
            Stopwatch sw = Stopwatch.StartNew();
            //using (var transaction = client.GetTransaction().Result)
            using (destination.IncommingMessages.Subscribe(WriteMessageId))
            {
                //SendMessages(destination, receiptBehavior, transaction).Wait();
                //transaction.Commit();

                Console.WriteLine("Subscribed to messages, Press enter to ack last one");
                Console.ReadLine();

                //lastMessage.Ack().Wait();
                Console.WriteLine("Ackd last message, press enter to end subscription and dispose client");
                Console.ReadLine();
            }


            client.Dispose();
            Console.WriteLine(sw.Elapsed);
            return;

            Console.ReadLine();
        }