Beispiel #1
0
        private static void Init(Message<T> msg, string topic, BatchMessageId batchMessageIdImpl, MessageMetadata msgMetadata, SingleMessageMetadata singleMessageMetadata, ReadOnlySequence<byte> payload, Option<EncryptionContext> encryptionCtx, IActorRef cnx, ISchema<T> schema, int redeliveryCount, bool poolMessage)
        {
            //msg._metadata.Clear();
            msg._metadata = new Metadata();
            msg._messageId = batchMessageIdImpl;
            msg._topic = topic;
            msg._cnx = cnx;
            msg._redeliveryCount = redeliveryCount;
            msg._encryptionCtx = encryptionCtx;
            msg._schema = schema;

            msg._poolMessage = poolMessage;
            // If it's not pool message then need to make a copy since the passed payload is 
            // using a ref-count buffer that we don't know when could release, since the 
            // Message is passed to the user. Also, the passed ByteBuf is coming from network 
            // and is backed by a direct buffer which we could not expose as a byte[]
            msg._payload = payload;//poolMessage ? payload.retain() : Unpooled.copiedBuffer(payload);
            msg._metadata.ReplicateTo = msgMetadata.ReplicateToes;
            if (singleMessageMetadata != null)
            {
                if (singleMessageMetadata.Properties.Count > 0)
                {
                    IDictionary<string, string> properties = new Dictionary<string, string>();
                    foreach (var entry in singleMessageMetadata.Properties)
                    {
                        properties[entry.Key] = entry.Value;
                    }
                    msg.Properties = properties.ToImmutableDictionary();
                }
                else
                {
                    msg.Properties = new Dictionary<string, string>();
                }
                if (singleMessageMetadata.ShouldSerializePartitionKey())
                {
                    msg._metadata.PartitionKeyB64Encoded = singleMessageMetadata.PartitionKeyB64Encoded;
                    msg._metadata.PartitionKey = singleMessageMetadata.PartitionKey;
                }
                else if (msgMetadata.ShouldSerializePartitionKey())
                {
                    msg._metadata.PartitionKey = string.Empty;
                    msg._metadata.PartitionKeyB64Encoded = false;
                }
                if (singleMessageMetadata.ShouldSerializeOrderingKey())
                {
                    msg._metadata.OrderingKey = singleMessageMetadata.OrderingKey;
                }
                else if (msgMetadata.ShouldSerializeOrderingKey())
                {
                    msg._metadata.OrderingKey = null;
                }

                if (singleMessageMetadata.ShouldSerializeEventTime())
                {
                    msg._metadata.EventTime = (long)singleMessageMetadata.EventTime;
                }

                if (singleMessageMetadata.ShouldSerializeSequenceId())
                {
                    msg._metadata.SequenceId = (long)singleMessageMetadata.SequenceId;
                }

                if (singleMessageMetadata.ShouldSerializeNullValue())
                {
                    msg._metadata.NullValue = singleMessageMetadata.NullValue;
                }

                if (singleMessageMetadata.ShouldSerializeNullPartitionKey())
                {
                    msg._metadata.NullPartitionKey = singleMessageMetadata.NullPartitionKey;
                }
            }
            else if (msgMetadata.Properties.Count > 0)
            {
                msg.Properties = msgMetadata.Properties.ToDictionary(x => x.Key, x=> x.Value).ToImmutableDictionary();
            }
            else
            {
                msg.Properties = new Dictionary<string, string>();
            }

            msg._metadata = EnsureMetadata(msgMetadata, msg._metadata);
        }
Beispiel #2
0
 internal Message(string topic, BatchMessageId batchMessageIdImpl, MessageMetadata msgMetadata, SingleMessageMetadata singleMessageMetadata, ReadOnlySequence<byte> payload, Option<EncryptionContext> encryptionCtx, IActorRef cnx, ISchema<T> schema) : this(topic, batchMessageIdImpl, msgMetadata, singleMessageMetadata, payload, encryptionCtx, cnx, schema, 0, false)
 {
 }
Beispiel #3
0
        internal Message(string topic, BatchMessageId batchMessageIdImpl, MessageMetadata batchMetadata, SingleMessageMetadata singleMessageMetadata, ReadOnlySequence<byte> payload, Option<EncryptionContext> encryptionCtx, IActorRef cnx, ISchema<T> schema, int redeliveryCount, bool keepMessageInDirectMemory)
        {
            Init(this, topic, batchMessageIdImpl, batchMetadata, singleMessageMetadata, payload, encryptionCtx, cnx, schema, redeliveryCount, keepMessageInDirectMemory);

        }
Beispiel #4
0
        public static Message<T> Create(string topic, BatchMessageId batchMessageIdImpl, MessageMetadata batchMetadata, SingleMessageMetadata singleMessageMetadata, ReadOnlySequence<byte> payload, Option<EncryptionContext> encryptionCtx, IActorRef cnx, ISchema<T> schema, int redeliveryCount, bool pooledMessage)
        {
            if (pooledMessage)
            {
                var msg = new Message<T>();
                Init(msg, topic, batchMessageIdImpl, batchMetadata, singleMessageMetadata, payload, encryptionCtx, cnx, schema, redeliveryCount, pooledMessage);
                return msg;
            }

            return new Message<T>(topic, batchMessageIdImpl, batchMetadata, singleMessageMetadata, payload, encryptionCtx, cnx, schema, redeliveryCount, pooledMessage);
        }