public static EndpointMessage AsEndpointMessage(this IMessage message, ISerializer serializer, string routingKey = "", Dictionary<string, object> routingHeaders = null)
        {
            TransportMessage transportMessage = new TransportMessage(new Message(message));

            byte[] body = serializer.SerializeToBytes(transportMessage);
            Dictionary<string, object> headers = routingHeaders ?? new Dictionary<string, object>() { { MessageInfo.GetContractId(transportMessage.Payload.Payload.GetType()), String.Empty } };
            EndpointMessage endpointMessage = new EndpointMessage(body, routingKey, headers);
            return endpointMessage;
        }
        public void Start()
        {
            try
            {
                isWorking = true;
                endpoint.Open();
                while (isWorking)
                {
                    List <EndpointMessage> rawMessages = new List <EndpointMessage>();
                    for (int i = 0; i < messageThreshold.Size; i++)
                    {
                        EndpointMessage rawMessage = null;
                        if (!endpoint.BlockDequeue(messageThreshold.Delay, out rawMessage))
                        {
                            break;
                        }

                        CronusMessage transportMessage = (CronusMessage)serializer.DeserializeFromBytes(rawMessage.Body);
                        var           subscribers      = subscriptions.GetInterestedSubscribers(transportMessage);
                        foreach (var subscriber in subscribers)
                        {
                            subscriber.Process(transportMessage);
                        }
                        rawMessages.Add(rawMessage);
                    }

                    endpoint.AcknowledgeAll();
                }
            }
            catch (EndpointClosedException ex)
            {
                log.DebugException("Endpoint Closed", ex);
            }
            catch (Exception ex)
            {
                log.ErrorException("Unexpected Exception.", ex);
            }
            finally
            {
                try
                {
                    endpoint.AcknowledgeAll();
                    endpoint.Close();
                }
                catch (EndpointClosedException ex)
                {
                    log.DebugException("Endpoint Closed", ex);
                }
                ScheduledStart = DateTime.UtcNow.AddMilliseconds(30);
            }
        }
Exemple #3
0
        protected override bool PublishInternal(T message, Dictionary <string, string> messageHeaders)
        {
            var cronusMessage = new CronusMessage(message, messageHeaders);

            byte[] body = serializer.SerializeToBytes(cronusMessage);
            Dictionary <string, object> routingHeaders = new Dictionary <string, object>()
            {
                { cronusMessage.Payload.GetType().GetContractId(), String.Empty }
            };
            EndpointMessage endpointMessage = new EndpointMessage(body, string.Empty, routingHeaders, cronusMessage.GetPublishDelay());

            transport.PipelineFactory
            .GetPipeline(message.GetType())
            .Push(endpointMessage);
            return(true);
        }