예제 #1
0
        public void Should_return_an_empty_array_for_no_headers()
        {
            var headers = new TransportMessageHeaders();

            headers.Add("Content-Type", null);
            headers.GetBytes().Length.ShouldEqual(0);
        }
		public void A_message_is_send_using_a_transport()
		{
			var headers = new TransportMessageHeaders();
			headers.Add("Content-Type", "application/vnd.masstransit+json");

			_bytes = headers.GetBytes();
		}
예제 #3
0
        public void A_message_is_send_using_a_transport()
        {
            var headers = new TransportMessageHeaders();

            headers.Add("Content-Type", "application/vnd.masstransit+json");

            _bytes = headers.GetBytes();
        }
예제 #4
0
        public void Send(ISendContext context)
        {
            using (var message = new Message())
            {
                if (!string.IsNullOrEmpty(context.MessageType))
                {
                    message.Label = context.MessageType.Length > 250 ? context.MessageType.Substring(0, 250) : context.MessageType;
                }

                message.Recoverable        = _address.IsRecoverable;
                message.UseDeadLetterQueue = true; // in case lack of permission message will be redirected to dead letter

                if (context.ExpirationTime.HasValue)
                {
                    DateTime value = context.ExpirationTime.Value;
                    message.TimeToBeReceived = value.Kind == DateTimeKind.Utc ? value - SystemUtil.UtcNow : value - SystemUtil.Now;
                }

                context.SerializeTo(message.BodyStream);

                var headers = new TransportMessageHeaders();

                if (!string.IsNullOrEmpty(context.ContentType))
                {
                    headers.Add("Content-Type", context.ContentType);
                }
                if (!string.IsNullOrEmpty(context.OriginalMessageId))
                {
                    headers.Add("Original-Message-Id", context.OriginalMessageId);
                }

                message.Extension = headers.GetBytes();

                try
                {
                    _connectionHandler.Use(connection => SendMessage(connection.Queue, message));

                    _address.LogSent(message.Id, context.MessageType);
                }
                catch (MessageQueueException ex)
                {
                    HandleOutboundMessageQueueException(ex);
                }
            }
        }
        public void Send(ISendContext context)
        {
            using (var message = new Message())
            {
                if (!string.IsNullOrEmpty(context.MessageType))
                    message.Label = context.MessageType.Length > 250 ? context.MessageType.Substring(0, 250) : context.MessageType;

                message.Recoverable = _address.IsRecoverable;
                message.UseDeadLetterQueue = true; // in case lack of permission message will be redirected to dead letter

                if (context.ExpirationTime.HasValue)
                {
                    DateTime value = context.ExpirationTime.Value;
                    message.TimeToBeReceived = value.Kind == DateTimeKind.Utc ? value - SystemUtil.UtcNow : value - SystemUtil.Now;
                }

                context.SerializeTo(message.BodyStream);

                var headers = new TransportMessageHeaders();

                if (!string.IsNullOrEmpty(context.ContentType))
                    headers.Add("Content-Type", context.ContentType);
                if (!string.IsNullOrEmpty(context.OriginalMessageId))
                    headers.Add("Original-Message-Id", context.OriginalMessageId);
                
                message.Extension = headers.GetBytes();

                try
                {
                    _connectionHandler.Use(connection => SendMessage(connection.Queue, message));

                    _address.LogSent(message.Id, context.MessageType);

                }
                catch (MessageQueueException ex)
                {
                    HandleOutboundMessageQueueException(ex);
                }
            }
        }
        public void Send(ISendContext context)
        {
            _connectionHandler.Use(connection =>
            {
                var
                message = new SqlMessage {
                    Label = context.MessageType
                };

                if (context.ExpirationTime.HasValue)
                {
                    DateTime value           = context.ExpirationTime.Value;
                    message.TimeToBeReceived = value.Kind == DateTimeKind.Utc ? value - SystemUtil.UtcNow : value - SystemUtil.Now;
                }

                var bodyStream = new MemoryStream();

                context.SerializeTo(bodyStream);

                message.Body = bodyStream.ToArray();

                var headers = new TransportMessageHeaders();

                if (!string.IsNullOrEmpty(context.ContentType))
                {
                    headers.Add("Content-Type", context.ContentType);
                }
                if (!string.IsNullOrEmpty(context.OriginalMessageId))
                {
                    headers.Add("Original-Message-Id", context.OriginalMessageId);
                }

                message.Extension = headers.GetBytes();

                connection.Queue.Enqueue(message);
                Console.WriteLine("{3} Sendt message: Label {1} Size {2}".FormatWith(message.Id, message.Label, message.Body.Length, Address.Uri));
            });
        }
예제 #7
0
        public void Send(ISendContext context)
        {
            using (var message = new Message())
            {
                if (!string.IsNullOrEmpty(context.MessageType))
                {
                    message.Label = context.MessageType.Length > 250 ? context.MessageType.Substring(0, 250) : context.MessageType;
                }

                message.Recoverable = true;

                if (context.ExpirationTime.HasValue)
                {
                    DateTime value = context.ExpirationTime.Value;
                    message.TimeToBeReceived = value.Kind == DateTimeKind.Utc ? value - SystemUtil.UtcNow : value - SystemUtil.Now;
                }

                context.SerializeTo(message.BodyStream);

                if (context.ContentType != null)
                {
                    var headers = new TransportMessageHeaders();
                    headers.Add("Content-Type", context.ContentType);

                    message.Extension = headers.GetBytes();
                }

                try
                {
                    _connectionHandler.Use(connection => SendMessage(connection.Queue, message));

                    if (_messageLog.IsDebugEnabled)
                    {
                        _messageLog.DebugFormat("SEND:{0}:{1}:{2}", _address.OutboundFormatName, message.Label, message.Id);
                    }
                }
                catch (MessageQueueException ex)
                {
                    HandleOutboundMessageQueueException(ex);
                }
            }
        }
		public void Send(ISendContext context)
		{
			using (var message = new Message())
			{
				if (!string.IsNullOrEmpty(context.MessageType))
					message.Label = context.MessageType.Length > 250 ? context.MessageType.Substring(0, 250) : context.MessageType;

				message.Recoverable = true;

				if (context.ExpirationTime.HasValue)
				{
					DateTime value = context.ExpirationTime.Value;
					message.TimeToBeReceived = value.Kind == DateTimeKind.Utc ? value - SystemUtil.UtcNow : value - SystemUtil.Now;
				}

				context.SerializeTo(message.BodyStream);

				if (context.ContentType != null)
				{
					var headers = new TransportMessageHeaders();
					headers.Add("Content-Type", context.ContentType);

					message.Extension = headers.GetBytes();
				}

				try
				{
					_connectionHandler.Use(connection => SendMessage(connection.Queue, message));

					if (_messageLog.IsDebugEnabled)
						_messageLog.DebugFormat("SEND:{0}:{1}:{2}", _address.OutboundFormatName, message.Label, message.Id);
				}
				catch (MessageQueueException ex)
				{
					HandleOutboundMessageQueueException(ex);
				}
			}
		}
예제 #9
0
        public static void QueueMessage <T>(T message) where T : class
        {
            string localQueueName = new Uri(QueueName).GetLocalName();

            ISendContext <T> sc = new SendContext <T>(message);
            var messageEnvelope = Envelope.Create(sc);

            messageEnvelope.DestinationAddress = QueueName;

            /* using (var mq = new System.Messaging.MessageQueue(localQueueName))
             * {
             *  mq.Send(messageEnvelope);
             *
             * }
             */

            var msmqMessage = new Message();

            try
            {
                if (!string.IsNullOrEmpty(sc.MessageType))
                {
                    msmqMessage.Label = sc.MessageType.Length > 250 ? sc.MessageType.Substring(0, 250) : sc.MessageType;
                }

                msmqMessage.Recoverable        = false;
                msmqMessage.UseDeadLetterQueue = true;

                if (sc.ExpirationTime.HasValue)
                {
                    DateTime dateTime = sc.ExpirationTime.Value;
                    msmqMessage.TimeToBeReceived = dateTime.Kind == DateTimeKind.Utc
                                                       ? dateTime - SystemUtil.UtcNow
                                                       : dateTime - SystemUtil.Now;
                }

                var serializer = new XmlMessageSerializer();

                // (Action<Stream>)(stream => serializer.Serialize<T>(stream, sc))

                sc.SetBodyWriter(stream => serializer.Serialize(stream, sc));
                sc.SerializeTo(msmqMessage.BodyStream);

                // msmqMessage.Body = messageEnvelope;

                var transportMessageHeaders = new TransportMessageHeaders();

                if (!string.IsNullOrEmpty(sc.ContentType))
                {
                    transportMessageHeaders.Add("Content-Type", sc.ContentType);
                }

                if (!string.IsNullOrEmpty(sc.OriginalMessageId))
                {
                    transportMessageHeaders.Add("Original-Message-Id", sc.OriginalMessageId);
                }

                msmqMessage.Extension = transportMessageHeaders.GetBytes();

                using (var mq = new MessageQueue(localQueueName))
                {
                    mq.Send(msmqMessage, MessageQueueTransactionType.None);
                }
            }
            finally
            {
                msmqMessage.Dispose();
            }
        }
		public void Should_return_an_empty_array_for_no_headers()
		{
			var headers = new TransportMessageHeaders();
			headers.Add("Content-Type", null);
			headers.GetBytes().Length.ShouldEqual(0);
		}