예제 #1
0
        /// <summary>
        /// Executes the step and sets the default headers
        /// </summary>
        public async Task Process(OutgoingStepContext context, Func <Task> next)
        {
            var message     = context.Load <Message>();
            var headers     = message.Headers;
            var messageType = message.Body.GetType();

            if (!headers.ContainsKey(Headers.MessageId))
            {
                headers[Headers.MessageId] = Guid.NewGuid().ToString();
            }

            if (_hasOwnAddress && !headers.ContainsKey(Headers.ReturnAddress))
            {
                headers[Headers.ReturnAddress] = _returnAddress;
            }

            headers[Headers.SentTime] = _rebusTime.Now.ToString("O");

            if (_hasOwnAddress)
            {
                headers[Headers.SenderAddress] = _senderAddress;
            }
            else
            {
                headers.Remove(Headers.SenderAddress);
            }

            if (!headers.ContainsKey(Headers.Type))
            {
                headers[Headers.Type] = _messageTypeMapper.GetMessageType(messageType);
            }

            await next();
        }
예제 #2
0
        /// <summary>
        /// Serializes the given <see cref="Message"/> into a <see cref="TransportMessage"/>
        /// </summary>
        public async Task <TransportMessage> Serialize(Message message)
        {
            var jsonText = JsonConvert.SerializeObject(message.Body, _settings);
            var bytes    = _encoding.GetBytes(jsonText);
            var headers  = message.Headers.Clone();

            headers[Headers.ContentType] = _encodingHeaderValue;

            if (!headers.ContainsKey(Headers.Type))
            {
                headers[Headers.Type] = _messageTypeMapper.GetMessageType(message.Body.GetType());
            }

            return(new TransportMessage(headers, bytes));
        }
예제 #3
0
 /// <summary>
 /// Returns the default topic name based on the "short assembly-qualified type name", which is
 /// an assembly- and namespace-qualified type name without assembly version and public key token info.
 /// </summary>
 public string GetTopic(Type eventType)
 {
     return(_messageTypeMapper.GetMessageType(eventType));
 }