Exemplo n.º 1
0
        /// <summary>
        ///   Sends a 'SEND' message
        /// </summary>
        public static void Send(this IStompClient client, string message, string destination)
        {
            var stompMsg = new StompMessage("SEND", message);

            stompMsg["destination"] = destination;

            client.Send(stompMsg);
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Sends an 'UNSUBSCRIBE' message
        /// </summary>
        public static void UnSubscribe(this IStompClient client, string destination)
        {
            var stompMsg = new StompMessage("UNSUBSCRIBE");

            stompMsg["destination"] = destination;

            client.Send(stompMsg);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles the CONNECT message
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="message">The message.</param>
        private static void OnStompConnect(IStompClient client, StompMessage message)
        {
            var result = new StompMessage("CONNECTED");

            result["session-id"] = client.SessionId.ToString();

            client.Send(result);
        }
Exemplo n.º 4
0
        /// <summary>
        ///   Excutes the action assigned to the message command
        /// </summary>
        /// <param name = "client"></param>
        /// <param name = "message"></param>
        private void OnClientMessage(IStompClient client, StompMessage message)
        {
            if (message == null || message.Command == null)
            {
                return;
            }

            if (client.SessionId == Guid.Empty)
            {
                client.SessionId = Guid.NewGuid();
            }

            Log.Info(string.Format("Processing command: {0} from client {1}", message.Command, client.SessionId));

            if (!_actions.ContainsKey(message.Command))
            {
                Log.Warn(string.Format("Client {0} sended an unknown command: {1}", client.SessionId, message.Command));
                return;
            }

            if (message.Command != "CONNECT" && client.IsConnected() == false)
            {
                Log.Info(string.Format("Client {0} was not connected before sending command: {1}", client.SessionId, message.Command));

                client.Send(new StompMessage("ERROR", "Please connect before sending '" + message.Command + "'"));
                return;
            }

            _actions[message.Command](client, message);

            // when a receipt is request, we send a receipt frame
            if (message.Command == "CONNECT" || message["receipt"] == string.Empty)
            {
                return;
            }
            var response = new StompMessage("RECEIPT");

            response["receipt-id"] = message["receipt"];
            client.Send(response);
        }
Exemplo n.º 5
0
        private void SendMessage(IStompClient client, string body, Guid messageId, string subscriptionId)
        {
            Log.Info(string.Format("Sending message to {0}", client.SessionId));
            Log.Debug(string.Format("message {0}", body));

            var stompMessage = new StompMessage("MESSAGE", body);

            stompMessage["message-id"]  = messageId.ToString();
            stompMessage["destination"] = Address;

            if (!string.IsNullOrEmpty(subscriptionId))
            {
                stompMessage["subscription"] = subscriptionId;
            }

            client.Send(stompMessage);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Handles the UNSUBSCRIBE message
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="message">The message.</param>
        private void OnStompUnsubscribe(IStompClient client, StompMessage message)
        {
            string destination = message["destination"];

            if (string.IsNullOrEmpty(destination))
            {
                return;
            }
            var queue = _queues.FirstOrDefault(q => q.Address == destination);

            if (queue == null || queue.Clients.Contains(client) == false)
            {
                client.Send(new StompMessage("ERROR", "You are not subscribed to queue '" + destination + "'"));
                return;
            }

            queue.RemoveClient(client);
        }
Exemplo n.º 7
0
        /// <summary>
        ///   Sends a 'CONNECT' message
        /// </summary>
        public static void Connect(this IStompClient client)
        {
            var stompMsg = new StompMessage("CONNECT");

            client.Send(stompMsg);
        }
Exemplo n.º 8
0
        private void SendMessage(IStompClient client, string body, Guid messageId, string subscriptionId)
        {
            Log.Info(string.Format("Sending message to {0}", client.SessionId));
            Log.Debug(string.Format("message {0}", body));

            var stompMessage = new StompMessage("MESSAGE", body);
            stompMessage["message-id"] = messageId.ToString();
            stompMessage["destination"] = Address;

            if (!string.IsNullOrEmpty(subscriptionId))
            {
                stompMessage["subscription"] = subscriptionId;
            }

            client.Send(stompMessage);
        }