Пример #1
0
        public override ObjectList <T> RequestList <T>(ChannelRequest request)
        {
            var stompRequest  = StompRequest.Create(request, _channelId, _configuration.ReplyTo, _configuration.Destination);
            var returnMessage = SendMessage(stompRequest);

            SecucardTrace.InfoSource("StompChannel.RequestList", returnMessage.EscapeCurlyBracets());
            var response = new Response(returnMessage);

            return(JsonSerializer.DeserializeJson <ObjectList <T> >(response.Data));
        }
Пример #2
0
        /// <summary>
        ///     Factory method to convert channelRequest to stompRequest
        /// </summary>
        public static StompRequest Create(ChannelRequest channelRequest, string channelId, string replyTo,
                                          string destinationBase)
        {
            var stompRequest = new StompRequest
            {
                AppId         = channelRequest.AppId,
                CorrelationId = DateTime.Now.Millisecond + "#" + Guid.NewGuid().ToString(),
                ReplayTo      = replyTo,
                Destination   = CreateDestination(channelRequest, destinationBase),
                Body          = CreateMessageBody(channelRequest)
            };

            return(stompRequest);
        }
Пример #3
0
        private string SendMessage(StompRequest stompRequest)
        {
            var token = GetToken();

            var frame = new StompFrame(StompCommands.Send);

            frame.Headers.Add(StompHeader.ReplyTo, stompRequest.ReplayTo);
            frame.Headers.Add(StompHeader.ContentType, "application/json");
            frame.Headers.Add(StompHeader.UserId, token);
            frame.Headers.Add(StompHeader.CorrelationId, stompRequest.CorrelationId);
            frame.Headers.Add(StompHeader.Destination, stompRequest.Destination);

            if (!string.IsNullOrWhiteSpace(stompRequest.AppId))
            {
                frame.Headers.Add(StompHeader.AppId, stompRequest.AppId);
            }

            if (!string.IsNullOrWhiteSpace(stompRequest.Body))
            {
                frame.Body = stompRequest.Body;
                frame.Headers.Add(StompHeader.ContentLength, frame.Body.ToUTF8Bytes().Length.ToString());
            }

            // only one send at a time
            lock (_lockSend)
            {
                CheckConnection(token);
                _stomp.SendFrame(frame);
            }

            string message   = null;
            var    endWaitAt = DateTime.Now.AddSeconds(_configuration.MessageTimeoutSec);

            while (message == null && DateTime.Now < endWaitAt)
            {
                SecucardTrace.Info("Waiting for Message with correlationId={0}", stompRequest.CorrelationId);
                message = PullMessage(stompRequest.CorrelationId, _configuration.MaxMessageAgeSec);
                Thread.Sleep(500);
            }
            if (message == null)
            {
                throw new MessageTimeoutException("No answer for " + stompRequest.CorrelationId + " received within " +
                                                  _configuration.MessageTimeoutSec + "s.");
            }

            return(message);
        }
Пример #4
0
        private bool?SendSessionRefresh()
        {
            var channelRequest = new ChannelRequest
            {
                Method   = ChannelMethod.Execute,
                Product  = "auth",
                Resource = "sessions",
                Action   = "refresh",
                ObjectId = "me"
            };

            var stompRequest = StompRequest.Create(channelRequest, _channelId, _configuration.ReplyTo,
                                                   _configuration.Destination);
            var returnMessage = SendMessage(stompRequest);

            var response = new Response(returnMessage);

            return(JsonSerializer.DeserializeJson <StompResult>(response.Data).Result);
        }