Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Azure Function Java support binding library #48

Merged
merged 13 commits into from
Feb 26, 2019
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,30 @@ ASALocalRun/
# MFractors (Xamarin productivity tool) working folder
.mfractor/

# Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
**/.vscode/*

# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar
*.factorypath

# Java output
**/target/*

# Java IDE
.idea/
*.iml
.classpath
.project
.settings/
.checkstyle
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ addons:
apt:
packages:
- libunwind8
- maven
script:
- "./build.sh --ci /p:BuildNumber=$((10000+TRAVIS_BUILD_NUMBER))"
- mvn clean package -f ./binding-library/java/pom.xml
51 changes: 51 additions & 0 deletions binding-library/java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# SignalR Service Library for Azure Java Functions
This repo contains SignalR serivce library for building Azure Java Functions. Visit the [complete documentation of Azure Functions - Java Developer Guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-java) for more details.

## Prerequisites

* Java 8
* [Azure Function Core Tools](https://github.com/Azure/azure-functions-core-tools) (V2)
* Maven 3.0 or above
* [Azure Function Maven Plugin](https://github.com/Microsoft/azure-maven-plugins/) (1.3.0-SNAPSHOT or above)

### Sample

Here is an example of a HttpTrigger Azure function using SignalR service in Java:

```java
package com.example;

import com.microsoft.azure.functions.*;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.signalr.*;
import com.microsoft.azure.functions.signalr.annotation.*;

public class Functions {
@FunctionName("negotiate")
public SignalRConnectionInfo negotiate(
@HttpTrigger(
name = "req",
methods = { HttpMethod.POST, HttpMethod.GET },
authLevel = AuthorizationLevel.ANONYMOUS)
HttpRequestMessage<Optional<String>> req,
@SignalRConnectionInfoInput(name = "connectionInfo", hubName = "simplechat") SignalRConnectionInfo connectionInfo) {

return connectionInfo;
}
}|
```
Take a look at [SimpleChatRoom](https://github.com/Azure/azure-functions-signalrservice-extension/tree/dev/samples/simple-chat/java) for other using cases.

# Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Copy link

@jdneo jdneo Feb 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two spaces before Most #Resolved

Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
83 changes: 83 additions & 0 deletions binding-library/java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.microsoft.azure.functions</groupId>
<artifactId>azure-functions-java-library-signalr</artifactId>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pragnagopa Would you help check if the groupId is good?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

<version>1.0-SNAPSHOT</version>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.0-SNAPSHOT [](start = 4, length = 31)

Will use 1.0.0 as release version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change to 1.0.0-SNAPSHOT

<packaging>jar</packaging>

<name>Microsoft Azure Functions Java SignalR Types</name>
<description>This package contains all Java interfaces and annotations to interact with Microsoft Azure functions runtime for SignalR Service.</description>
<url>https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-signalr-service</url>
<organization>
<name>Microsoft Azure</name>
<url>https://azure.microsoft.com</url>
</organization>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<azure.functions.java.library.version>1.3.0-SNAPSHOT</azure.functions.java.library.version>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.3.0-SNAPSHOT [](start = 46, length = 14)

Will update to release version(should be 1.3.0) after library published and before checked-in.

Copy link
Member

@pragnagopa pragnagopa Feb 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to release a SNAPSHOT version first to enable E2E testing before releasing the official version. This is the same release process we follow of the library #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the advise. Will do.


In reply to: 259939957 [](ancestors = 259939957)

</properties>

<licenses>
<license>
<name>MIT License</name>
<url>https://opensource.org/licenses/MIT</url>
<distribution>repo</distribution>
</license>
</licenses>

<developers>
<developer>
<id>anthonychu</id>
<name>Anthony Chu</name>
<email>Anthony.Chu@microsoft.com</email>
</developer>
<developer>
<id>JialinXin</id>
<name>Jialin Xin</name>
<email>jixin@microsoft.com</email>
</developer>
</developers>

<repositories>
<repository>
<id>maven.snapshots</id>
<name>Maven Central Snapshot Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.microsoft.azure.functions</groupId>
<artifactId>azure-functions-java-library</artifactId>
<version>${azure.functions.java.library.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.functions.signalr;

/**
* <p>
* SignalR connection information (used with SignalRConnectionInfo input binding)
* </p>
*
* @since 1.0.0
*/
public class SignalRConnectionInfo {
/**
* SignalR Sevice endpoint
*/
public String url;

/**
* Access token to use to connect to SignalR Service endpoint
*/
public String accessToken;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.functions.signalr;

/**
* <p>
* SignalR group action (used with SignalR output binding)
* </p>
*
* @since 1.0.0
*/
public class SignalRGroupAction {
/**
* User to add to or remove from group
*/
public String userId = "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this used? Can you please add test/sample code?

Copy link
Contributor Author

@JialinXin JialinXin Feb 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check sample here: https://github.com/Azure/azure-functions-signalrservice-extension/pull/49/files. Do you suggest to add sample as comments in this file?


In reply to: 259940432 [](ancestors = 259940432)


/**
* Group to add user to or remove user from
*/
public String groupName = "";

/**
* Action to take ("add" or "remove")
*/
public String action = "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.functions.signalr;

import java.util.ArrayList;
import java.util.List;

/**
* <p>
* SignalR Message to use with SignalR output binding
* </p>
*
* @since 1.0.0
*/
public class SignalRMessage {
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. How is this used? Can you please add test/sample code?

* User to send the message to
*/
public String userId = "";

/**
* Group to send the message to
*/
public String groupName = "";

/**
* Target method to invoke on clients
*/
public String target;

/**
* Arguments to pass to target method
*/
public List<Object> arguments = new ArrayList<Object>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.functions.signalr.annotation;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.ElementType;

import com.microsoft.azure.functions.annotation.CustomBinding;

/**
* <p>Place this on a parameter to obtain a SignalRConnectionInfo object.
* The parameter type can be one of the following:</p>
*
* <ul>
* <li>SignalRConnectionInfo type</li>
* </ul>
*/
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@CustomBinding(direction = "in", name = "", type = "SignalRConnectionInfo")
public @interface SignalRConnectionInfoInput {

/**
* The variable name used in function.json.
* @return The variable name used in function.json.
*/
String name();

/**
* Defines the app setting name that contains the Azure SignalR Service connection string.
* @return The app setting name of the connection string.
*/
String connectionStringSetting() default "";

/**
* Defines the name of the hub in Azure SignalR Service to which to connect.
* @return The hub name.
*/
String hubName();

/**
* Defines the user ID to associate with the connection. Typically uses a
* binding expression such as {x-ms-client-principal-name} (the principal name
* from App Service Authentication).
* @return The user ID.
*/
String userId() default "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.functions.signalr.annotation;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.ElementType;

import com.microsoft.azure.functions.annotation.CustomBinding;

/**
* <p>Output type to Azure SignalR Service</p>
*/
@Target({ ElementType.PARAMETER, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@CustomBinding(direction = "out", name = "", type = "SignalR")
public @interface SignalROutput {
/**
* The variable name used in function.json.
* @return The variable name used in function.json.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anthonychu - Have you tested this? I would like to make sure there are no changes needed for this work on the worker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With help from Anthony, I've tested this. By replacing worker(build from dev branch) in the function core tools and latest maven plugin, it could work. Sample code can be found in this PR: https://github.com/Azure/azure-functions-signalrservice-extension/pull/49/files


In reply to: 259940994 [](ancestors = 259940994)

*/
String name();

/**
* Defines the app setting name that contains the Azure SignalR Service connection string.
* @return The app setting name of the connection string.
*/
String connectionStringSetting() default "";

/**
* Defines the name of the hub in Azure SignalR Service to which to connect.
* @return The hub name.
*/
String hubName();
}