Reputation: 689
I am not able to run my azure function locally written in java which should work based on BlobTrigger.
I am facing the following error:
A host error has occurred
Microsoft.WindowsAzure.Storage: No connection could be made because the target machine actively refused it. System.Net.Http: No connection could be made because the target machine actively refused it. System.Private.CoreLib: No connection could be made because the target machine actively refused it.
Here is my code:
public class Function {
@FunctionName("BlobTrigger")
@StorageAccount("reseaudiag")
public void blobTrigger(
@BlobTrigger(name = "content", path = "filer/{fileName}", dataType = "binary",
connection = "AzureWebJobsDashboard"
) byte[] content,
@BindingName("fileName") String fileName,
final ExecutionContext context
) {
context.getLogger().info("Java Blob trigger function processed a blob.\n Name: " + fileName + "\n Size: " + content.length + " Bytes");
}
}
Based on initial run only, I can start implementing the logic but I am blocked to run the basic step itself.
Here is my local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=XXX;AccountKey=confidential;EndpointSuffix=core.windows.net",
"AzureWebJobsDashboard": "UseDevelopmentStorage=true",
"DataConnectionString": "UseDevelopmentStorage=true",
"ContainerName": "filer"
},
"ConnectionStrings": {
"PlantaoEntities": {
"ConnectionString": "DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=confidential;EndpointSuffix=core.windows.net",
"ProviderName": "System.Data.EntityClient"
}
}
}
Thank you.
Upvotes: 1
Views: 6943
Reputation: 105
I had the same problem and it really took me almost 2 days to fix it.
This worked for me: https://stackoverflow.com/a/57757140/6688910
Basically, I had to delete the database located at %USERPROFILE%/AzureEmulatorStorageDb[Number]. Where AzureEmulatorStrageDb[somenumber] is the database it has generated.
Next, using cmd, navigate to Emulator folder
cd C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator
Then initialize the emulator by running the following command
AzureStorageEmulator.exe init /forceCreate
Now you should be able to run azure functions without any problems.
Upvotes: 1
Reputation: 5549
Your code is almost correct. You need to specify a correct connection in your blob trigger.
Here is my successful sample:
package com.function;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;
public class Function {
@FunctionName("BlobTrigger")
public void run(
@BlobTrigger(name = "trigger", path = "test/{fileName}", dataType = "binary", connection = "AzureWebJobsStorage") byte[] content,
@BindingName("fileName") String fileName,
final ExecutionContext context) {
context.getLogger().info("Blob: " + fileName + " -> Length: " + content.length);
}
}
I use the "AzureWebJobsStorage" connection in my code, so I need to set a connection string in the local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=storagetest789;AccountKey=*******w==;EndpointSuffix=core.windows.net",
"FUNCTIONS_WORKER_RUNTIME": "java"
}
}
Then, run the function locally and upload a file to the storage, I will get outputs as following:
Note:
When you publish your app to Azure Function App, the settings in your local setting file will not be updated to the cloud. You need to manually update them.
Please ensure that you have made your storage account accessible. If you enable firewall for your storage account, you need to add your client IP for local test, and allow trusted Microsoft Services to access your storage.
And then you can modify settings here:
Upvotes: 1