long GetEventSizeForBatch(EventData eventData)
        {
            // Create AMQP message here.
            var amqpMessage = AmqpMessageConverter.EventDataToAmqpMessage(eventData);

            AmqpMessageConverter.UpdateAmqpMessagePartitionKey(amqpMessage, this.PartitionKey);

            // Calculate overhead depending on the message size.
            // Overhead is smaller for messages smaller than 256 bytes.
            long overhead = amqpMessage.SerializedMessageSize < 256 ? 5 : 8;

            // We can use the same AMQP message unless diagnostics is enabled.
            // Diagnostics extension will stamp message with an id on the Send call.
            if (!EventHubsDiagnosticSource.IsEnabledForSendActivity)
            {
                eventData.AmqpMessage = amqpMessage;
            }
            else
            {
                // Reserve overhead for diagnostic-id property.
                overhead += DiagnosticsIdOverhead;
            }

            return(amqpMessage.SerializedMessageSize + overhead);
        }
        long GetSize(EventData eventData)
        {
            // Create AMQP message here. We will use the same message while sending to save compute time.
            var amqpMessage = AmqpMessageConverter.EventDataToAmqpMessage(eventData);

            AmqpMessageConverter.UpdateAmqpMessagePartitionKey(amqpMessage, this.PartitionKey);
            eventData.AmqpMessage = amqpMessage;
            return(eventData.AmqpMessage.SerializedMessageSize);
        }
Exemplo n.º 3
0
        long GetEventSizeForBatch(EventData eventData)
        {
            // Create AMQP message here. We will use the same message while sending to save compute time.
            var amqpMessage = AmqpMessageConverter.EventDataToAmqpMessage(eventData);
            AmqpMessageConverter.UpdateAmqpMessagePartitionKey(amqpMessage, this.PartitionKey);
            eventData.AmqpMessage = amqpMessage;

            // Calculate overhead depending on the message size. 
            // Overhead is smaller for messages smaller than 256 bytes.
            long overhead = eventData.AmqpMessage.SerializedMessageSize < 256 ? 5 : 8;

            return eventData.AmqpMessage.SerializedMessageSize + overhead;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new <see cref="EventDataBatch"/>.
        /// </summary>
        /// <param name="maxSizeInBytes">The maximum size allowed for the batch</param>
        /// <param name="partitionKey">Partition key associate with the batch</param>
        public EventDataBatch(long maxSizeInBytes, string partitionKey = null)
        {
            this.PartitionKey = partitionKey;
            this.maxSize = Math.Min(maxSizeInBytes, MaxSizeLimit);
            this.eventDataList = new List<EventData>();

            // Reserve for wrapper message.
            using (var batchMessage = AmqpMessage.Create())
            {
                batchMessage.MessageFormat = AmqpConstants.AmqpBatchedMessageFormat;
                AmqpMessageConverter.UpdateAmqpMessagePartitionKey(batchMessage, partitionKey);
                this.currentSize = batchMessage.SerializedMessageSize;
            }
        }