I want to connect to a Cosmos DB in Azure from Azure Functions written in Java Code in an Maven Project (written in Intellij). The whole thing should be triggered by a HTTP request. The HTTP request part works great. While I just want to read from the database this tutorial still appeared to be a good starting point. The code should look something like this:
@FunctionName("processSensorData")
public void processSensorData(
@EventHubTrigger(
name = "msg",
eventHubName = "", // blank because the value is included in the connection string
cardinality = Cardinality.ONE,
connection = "EventHubConnectionString")
TelemetryItem item,
@CosmosDBOutput(
name = "databaseOutput",
databaseName = "TelemetryDb",
collectionName = "TelemetryInfo",
connectionStringSetting = "CosmosDBConnectionString")
OutputBinding<TelemetryItem> document,
final ExecutionContext context) {...
Now if I create a new Azure Function Project in Intelij of type HttpTigger and a add an @CosmosDBInput binding (or @CosmosDBOutput binding it does not matter), the system tells me that the parameter "connectionStringSetting" could not be resolved. It appears that a "connection" parameter is required.
I searched on different sources through the internet and asked Chat GPT but everywhere only the connectionStringSetting version is shown. So i am now very confused...
I assume that it is some sorts of version problem? Like e.g. the old version used connectionStringSetting and the later version used the connection parameter?
Also if I directly create an @CosmosDBTrigger function it still appears that he uses the connection parameter.
Furthermore I can add the complete code but it is really just the generated class and other files when i create a Azure Function in Intelij. As the rest works great I assume the problem is with the @CosmosDBTrigger annotation.
Also on first glance it appears that these two parameters work very similar.
In in short: What could be the reason that my code uses the connection parameter and not the connectionStringSetting parameter?
To be clear I am not asking how I can connect to Azure with the connection parameter but I want to understand why I get a different parameter than every source on the internet? (Is it save to use? Am I using an deprecated version with out knowing it? Which of the many versions in the pom.xml is the deprecated one (if any)? etc.)
Thanks for bringing this up. The Tutorial seems outdated, sorry for the bad experience.
The Cosmos DB Bundle/Extension that provides support for Input/Output/Trigger bindings was updated in 2023.
There is a migration guide available here: https://learn.microsoft.com/azure/azure-functions/migrate-cosmos-db-version-3-version-4?tabs=isolated-process&pivots=programming-language-java
In your case, the code should look like:
@FunctionName("processSensorData")
public void processSensorData(
@EventHubTrigger(
name = "msg",
eventHubName = "", // blank because the value is included in the connection string
cardinality = Cardinality.ONE,
connection = "EventHubConnectionString")
TelemetryItem item,
@CosmosDBOutput(
name = "databaseOutput",
databaseName = "TelemetryDb",
containerName = "TelemetryInfo",
connection = "CosmosDBConnectionString")
OutputBinding<TelemetryItem> document,
final ExecutionContext context) {...
We'll work on updating that tutorial.