I'm struggling to understand why I'm receiving the following error with my Azure function.
Error:
Error indexing method 'IntegrationFunction' Can't convert from type 'Microsoft.Azure.EventHubs.EventData
The function is reading data from an Azure Service Bus and transforming it before posting it to an Azure Event Hub and another Azure Service Bus.
Function:
[FunctionName("IntegrationFunction")]
[return: ServiceBus("%Transactions:SB:Transactions:ProcessorUpdateQueue%", Connection = "Transactions:SB:Transactions")]
public async Task<ServiceBusMessage> Run(
[ServiceBusTrigger(
"%Transactions:SB:Transactions:ReceiveTopic%",
"%Transactions:SB:Transactions:AnalyticsTopicSubscription%",
Connection = "Transactions:SB:Transactions")]
string inputMsg,
[EventHub("%Transactions:EVH:Transactions:Hub%", Connection = "Transactions:EVH:Transactions")] IAsyncCollector<EventData> outputEvent,
ILogger log)
{
if (string.IsNullOrWhiteSpace(inputMsg))
{
throw new ArgumentNullException(nameof(inputMsg));
}
log.LogInformation($"Service bus topic trigger function processing message: {inputMsg}");
var retailTransaction = JsonConvert.DeserializeObject<RetailTransaction>(
inputMsg,
JsonSerialisationUtils.SerialiserSettings);
if (retailTransaction == null)
{
throw new JsonException("Deserialized transaction was null");
}
try
{
// Transform
var transaction = retailTransaction.ToDto();
// Post to event hub
await outputEvent.AddAsync(new EventData(ToByteArray(transaction)));
log.LogInformation($"Transaction {transaction.TransactionNumber} processed.");
// Post to service bus
return retailTransaction.ToUpdateServiceBusMessage(processorId);
}
catch (Exception e)
{
log.LogError(e, "Error mapping transaction.");
}
return null;
}
You need to use
Azure.Messaging.EventHubsfor extension version 5.x+. Thanks @Jesse Squire for the comment.You can also refer to the MS Doc which says the same.
.csproj-
Output-
Event Hub-
2nd Service Bus-