/// <summary>Helper method to convert from DateTime to AmqpTimestamp.</summary> /// <param name="datetime">The datetime.</param> /// <returns>The AmqpTimestamp.</returns> internal static AmqpTimestamp ToAmqpTimestamp(this DateTime datetime) { var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var unixTime = (datetime.ToUniversalTime() - epoch).TotalSeconds; var timestamp = new AmqpTimestamp((long)unixTime); return timestamp; }
public void Copying() { const String appId = "app-id"; const String clusterId = "cluster-id"; const String type = "type"; const String contentEncoding = "UTF-8"; const String contentType = "application/xml"; const String correlationId = "123"; const Byte deliveryMode = 2; const String expiration = "60000"; const String messageId = "456"; const Byte priority = 3; const String userId = "me"; const String replyTo = "amqp://my.host"; var timestamp = new AmqpTimestamp(1445843868L); var properties = new BasicProperties { AppId = appId, ClusterId = clusterId, Type = type, ContentEncoding = contentEncoding, ContentType = contentType, CorrelationId = correlationId, DeliveryMode = deliveryMode, Expiration = expiration, MessageId = messageId, Priority = priority, UserId = userId, ReplyTo = replyTo, Headers = new Dictionary<String, Object> { { "h", "a" } }, Timestamp = timestamp }; var copy = properties.Copy(); Assert.Equal(appId, copy.AppId); Assert.Equal(clusterId, copy.ClusterId); Assert.Equal(type, copy.Type); Assert.Equal(contentEncoding, copy.ContentEncoding); Assert.Equal(contentType, copy.ContentType); Assert.Equal(correlationId, copy.CorrelationId); Assert.Equal(deliveryMode, copy.DeliveryMode); Assert.Equal(expiration, copy.Expiration); Assert.Equal(messageId, copy.MessageId); Assert.Equal(priority, copy.Priority); Assert.Equal(userId, copy.UserId); Assert.Equal(replyTo, copy.ReplyTo); Assert.Equal(PublicationAddress.Parse(replyTo), copy.ReplyToAddress); Assert.Equal(1, copy.Headers.Count); Assert.True(copy.Headers.ContainsKey("h")); Assert.Equal("a", copy.Headers["h"]); Assert.Equal(timestamp, copy.Timestamp); }
public abstract void HandleMessage(string type, string messageId, AmqpTimestamp timestamp, string textMessage, long deliveryTag, bool isRedelivery);
public static void WriteTimestamp(NetworkBinaryWriter writer, AmqpTimestamp val) { // 0-9 is afaict silent on the signedness of the timestamp. // See also MethodArgumentReader.ReadTimestamp and AmqpTimestamp itself WriteLonglong(writer, (ulong)val.UnixTime); }
public void WriteTimestamp(AmqpTimestamp val) { BitFlush(); WireFormatting.WriteTimestamp(m_writer, val); }
public static DateTime AmqpTimestampToDateTime (AmqpTimestamp ats) { DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0); return epoch.AddSeconds (ats.UnixTime).ToLocalTime (); }
public override void ReadPropertiesFrom(RabbitMQ.Client.Impl.ContentHeaderPropertyReader reader) { m_contentType_present = reader.ReadPresence(); m_contentEncoding_present = reader.ReadPresence(); m_headers_present = reader.ReadPresence(); m_priority_present = reader.ReadPresence(); m_timestamp_present = reader.ReadPresence(); reader.FinishPresence(); if (m_contentType_present) { m_contentType = reader.ReadShortstr(); } if (m_contentEncoding_present) { m_contentEncoding = reader.ReadShortstr(); } if (m_headers_present) { m_headers = reader.ReadTable(); } if (m_priority_present) { m_priority = reader.ReadOctet(); } if (m_timestamp_present) { m_timestamp = reader.ReadTimestamp(); } }
public override void ReadPropertiesFrom(RabbitMQ.Client.Impl.ContentHeaderPropertyReader reader) { m_contentType_present = reader.ReadPresence(); m_contentEncoding_present = reader.ReadPresence(); m_headers_present = reader.ReadPresence(); m_deliveryMode_present = reader.ReadPresence(); m_priority_present = reader.ReadPresence(); m_correlationId_present = reader.ReadPresence(); m_replyTo_present = reader.ReadPresence(); m_expiration_present = reader.ReadPresence(); m_messageId_present = reader.ReadPresence(); m_timestamp_present = reader.ReadPresence(); m_type_present = reader.ReadPresence(); m_userId_present = reader.ReadPresence(); m_appId_present = reader.ReadPresence(); m_clusterId_present = reader.ReadPresence(); reader.FinishPresence(); if (m_contentType_present) { m_contentType = reader.ReadShortstr(); } if (m_contentEncoding_present) { m_contentEncoding = reader.ReadShortstr(); } if (m_headers_present) { m_headers = reader.ReadTable(); } if (m_deliveryMode_present) { m_deliveryMode = reader.ReadOctet(); } if (m_priority_present) { m_priority = reader.ReadOctet(); } if (m_correlationId_present) { m_correlationId = reader.ReadShortstr(); } if (m_replyTo_present) { m_replyTo = reader.ReadShortstr(); } if (m_expiration_present) { m_expiration = reader.ReadShortstr(); } if (m_messageId_present) { m_messageId = reader.ReadShortstr(); } if (m_timestamp_present) { m_timestamp = reader.ReadTimestamp(); } if (m_type_present) { m_type = reader.ReadShortstr(); } if (m_userId_present) { m_userId = reader.ReadShortstr(); } if (m_appId_present) { m_appId = reader.ReadShortstr(); } if (m_clusterId_present) { m_clusterId = reader.ReadShortstr(); } }
public override void HandleMessage(string type, string messageId, AmqpTimestamp timestamp, string textMessage, long deliveryTag, bool isRedelivery) { this._exchangeListener.FilteredDispatch(type, textMessage); }
public override void HandleMessage(string type, string messageId, AmqpTimestamp timestamp, byte[] binaryMessage, long deliveryTag, bool isRedelivery) { this._exchangeListener.FilteredDispatch(type, Encoding.UTF8.GetString(binaryMessage)); }
public override void ReadArgumentsFrom(RabbitMQ.Client.Impl.MethodArgumentReader reader) { m_ticket = reader.ReadShort(); m_destination = reader.ReadShortstr(); m_redelivered = reader.ReadBit(); m_immediate = reader.ReadBit(); m_ttl = reader.ReadLonglong(); m_priority = reader.ReadOctet(); m_timestamp = reader.ReadTimestamp(); m_deliveryMode = reader.ReadOctet(); m_expiration = reader.ReadTimestamp(); m_exchange = reader.ReadShortstr(); m_routingKey = reader.ReadShortstr(); m_messageId = reader.ReadShortstr(); m_correlationId = reader.ReadShortstr(); m_replyTo = reader.ReadShortstr(); m_contentType = reader.ReadShortstr(); m_contentEncoding = reader.ReadShortstr(); m_userId = reader.ReadShortstr(); m_appId = reader.ReadShortstr(); m_transactionId = reader.ReadShortstr(); m_securityToken = reader.ReadLongstr(); m_applicationHeaders = reader.ReadTable(); m_body = reader.ReadContent(); }
public MessageTransfer( ushort initTicket, string initDestination, bool initRedelivered, bool initImmediate, ulong initTtl, byte initPriority, AmqpTimestamp initTimestamp, byte initDeliveryMode, AmqpTimestamp initExpiration, string initExchange, string initRoutingKey, string initMessageId, string initCorrelationId, string initReplyTo, string initContentType, string initContentEncoding, string initUserId, string initAppId, string initTransactionId, byte[] initSecurityToken, System.Collections.IDictionary initApplicationHeaders, byte[] initBody) { m_ticket = initTicket; m_destination = initDestination; m_redelivered = initRedelivered; m_immediate = initImmediate; m_ttl = initTtl; m_priority = initPriority; m_timestamp = initTimestamp; m_deliveryMode = initDeliveryMode; m_expiration = initExpiration; m_exchange = initExchange; m_routingKey = initRoutingKey; m_messageId = initMessageId; m_correlationId = initCorrelationId; m_replyTo = initReplyTo; m_contentType = initContentType; m_contentEncoding = initContentEncoding; m_userId = initUserId; m_appId = initAppId; m_transactionId = initTransactionId; m_securityToken = initSecurityToken; m_applicationHeaders = initApplicationHeaders; m_body = initBody; }
protected void SetMessageExpirationTimespan(IBasicProperties props, TimeSpan expiration) { // Once setted in props, expiration will be hanbled by RabbitMQ var timestamp = new AmqpTimestamp(DateTime.Now.ToUnixTime()); props.Timestamp = timestamp; if (expiration != default(TimeSpan)) props.Expiration = expiration.TotalMilliseconds.ToString(CultureInfo.InvariantCulture); }