We are using SendBatch() method of Azure service bus SDK 3.1.7 to send data to Azure Event Hub. Following is the code snippet :
foreach (var packet in transformedPackets)
{
EventData eventData = new EventData(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(packet, settings)));;
try
{
eventData.Properties.Add(AppConstants.TenantDeploymentUniqueIdKey, tenantDeploymentUniqueId);
eventData.Properties.Add(AppConstants.DataTypeKey, DataTypeKey);
byteCount += eventData.SerializedSizeInBytes;
if (byteCount > MaxBatchSize)
{
sender.SendBatch(transformedMessages);
transformedMessages.Clear();
byteCount = eventData.SerializedSizeInBytes;
}
transformedMessages.Add(eventData);
}
catch (System.Exception)
{
eventData.Dispose();
throw;
}
}
Event after checking the SerializedSizeInBytes property before adding the event data to the batch (Maximum allowed limit : 256 KB), we are getting the following exception :
The received message (delivery-id:0, size:262279 bytes) exceeds the limit (262144 bytes) currently allowed on the link.
at Microsoft.ServiceBus.Common.ExceptionDispatcher.Throw(Exception exception)
at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
at Microsoft.ServiceBus.Common.AsyncResult1.End(IAsyncResult asyncResult)
at Microsoft.ServiceBus.Messaging.MessageSender.RetrySenderEventDataAsyncResult.End(IAsyncResult r)
at Microsoft.ServiceBus.Messaging.MessageSender.EndSendEventData(IAsyncResult result)
at Microsoft.ServiceBus.Messaging.EventHubSender.SendBatch(IEnumerable
1 eventDataList)