示例#1
0
        public async void Dispose()
        {
            // Register for receipt
            var subscription = IncommingMessages.GetObservable("RECEIPT")
                               .Where(m => m.Headers.Any(h => h.Key == "receipt-id" && h.Value.ToString() == "disconnect-msg"));

            using (var lateSubscriber = new LateSubscriber <IMessage>(subscription))
            {
                // Dispose nicely, Send Discnonect message and wait for receipt.
                await SendMessage(new MessageBuilder("DISCONNECT").Header("receipt", "disconnect-msg").WithoutBody());

                var message = lateSubscriber.RecordedItems.FirstAsync().Wait();
            }

            _disposed = true;

            _messageSerializer.Dispose();
            _incommingMessagesSubject.Dispose();
            _outgoingMessagesSubject.Dispose();
            _client.Close();
        }
示例#2
0
        public StompTransport(string address, int port)
        {
            _client = new TcpClient();
            _client.Connect(address, port);

            _messageFactory    = new StreamMessageFactory(new StreamReader(_client.GetStream(), ASCII8BitEncoding));
            _messageSerializer =
                new MessageSerializerQueue(
                    new StreamMessageSerializer(new StreamWriter(_client.GetStream(), ASCII8BitEncoding)));

            _incommingMessageRouter = new MessageRouter(_incommingMessagesSubject);

            Task.Factory.StartNew(ReadLoop);

            using (var lateSubscriber = new LateSubscriber <IMessage>(IncommingMessages.GetObservable("CONNECTED")))
            {
                SendMessage(new MessageBuilder("CONNECT").Header("accept-version", 1.2).WithoutBody()).Wait();

                lateSubscriber.RecordedItems.FirstAsync().Wait();
            }
        }