- Follow the Configure your local environment instructions for Java.
- Install the .NET SDK
- Create a Java function project with
mvn archetype:generate -DarchetypeGroupId=com.microsoft.azure -DarchetypeArtifactId=azure-functions-archetype -DjavaVersion=8
- Remove the
test
folder for now. - Install the Redis Extension (manually for now, while the extension has not been added to the Microsoft.Azure.Functions.ExtensionBundle)
- Remove
extensionBundle
fromhost.json
- Run
func extensions install --package Microsoft.Azure.WebJobs.Extensions.Redis --version <version>
<version>
should be the latest version of the extension from NuGet
- Add the Java library for Redis bindings to the
pom.xml
file:<dependency> <groupId>com.microsoft.azure.functions</groupId> <artifactId>azure-functions-java-library-redis</artifactId> <version>[0.0.0,)</version> </dependency>
- Remove
- Replace the existing
Function.java
file with the following code:import com.microsoft.azure.functions.*; import com.microsoft.azure.functions.annotation.*; import com.microsoft.azure.functions.redis.annotation.*; public class Function { @FunctionName("PubSubTrigger") public void PubSubTrigger( @RedisPubSubTrigger( name = "message", connection = "Redis", channel = "pubsubTest") String message, final ExecutionContext context) { context.getLogger().info("Java function triggered on pub/sub message '" + message + "' from channel 'pubsubTest'."); } }
- Set up an Azure Cache for Redis instance or install Redis locally.
- Add the connection string from your Redis instance to your
local.settings.json
file. It should look something like this:{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "", "FUNCTIONS_WORKER_RUNTIME": "java", "Redis": "<connectionString>" } }
- Start the function locally:
mvn clean package mvn azure-functions:run
- Connect to your Redis cache using redis-cli, RedisInsight or some other Redis client.
- Publish a message to the channel
pubsubTest
:PUBLISH pubsubTest testing
- Your function should trigger!