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

Java support #111

Merged
merged 7 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions binding-library/java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?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-rabbitmq</artifactId>
<version>1.0.0-beta</version>
<packaging>jar</packaging>
<parent>
<groupId>com.microsoft.maven</groupId>
<artifactId>java-8-parent</artifactId>
<version>8.0.1</version>
</parent>

<name>Microsoft Azure Functions Java RabbitMQ types</name>
<description>This package contains all Java interfaces and annotations to interact with Microsoft Azure Functions runtime for RabbitMQ Service.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-compiler.version>3.8.0</maven-compiler.version>
<maven-source.version>3.0.1</maven-source.version>
<maven-javadoc.version>3.0.1</maven-javadoc.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<azure.functions.java.library.version>1.3.0</azure.functions.java.library.version>
</properties>

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

<scm>
<connection>scm:git:https://github.com/Azure/azure-functions-rabbitmq-extension</connection>
<developerConnection>scm:git:[email protected]:Azure/azure-functions-rabbitmq-extension</developerConnection>
<url>https://github.com/Azure/azure-functions-rabbitmq-extension</url>
<tag>HEAD</tag>
</scm>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<name>Sonatype Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<uniqueVersion>true</uniqueVersion>
<layout>default</layout>
</snapshotRepository>
</distributionManagement>

<developers>
<developer>
<id>pragnagopa</id>
<name>Pragna Gopa</name>
<email>[email protected]</email>
</developer>
<developer>
<id>cachai2</id>
<name>Cary Chai</name>
<email>[email protected]</email>
</developer>
<developer>
<id>yojagad</id>
<name>Yogesh Jagadeesan</name>
<email>[email protected]</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>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>4.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc.version}</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* 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.rabbitmq.annotation;

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

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

/**
* <p>Place this on a parameter whose value should be set in order for an event to be enqueued to a rabbitMQ queue.
* The parameter can be one of the following</p>
*
* <ul>
* <li>Any native Java types such as int, String, byte[]</li>
* <li>Any POJO type</li>
* </ul>
* <p>The following example is a Java function that uses a RabbitMQ trigger and output binding.</p>
*
* <pre>{@literal @}FunctionName("RabbitMQExample")
* public void run(
* {@literal @}@RabbitMQTrigger(
* connectionStringSetting = "ConnectionString",
* queueName = "TestQueue"
* ) String input,
* {@literal@}@RabbitMQOutput(
* connectionStringSetting = "ConnectionString",
* queueName = "hello"
* ) OutputBinding<String> output,
* final ExecutionContext context
* ) {
* context.getLogger().info("Java RabbitMQ trigger processed a request." + input);
* output.setValue(input);
* }</pre>
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.METHOD})
@CustomBinding(direction = "out", name = "outputMessage", type = "rabbitMq")
public @interface RabbitMQOutput {

/**
* The setting name of connection string.
* @return The connection string setting name from app settings.
*/
String connectionStringSetting() default "";

/**
* The host name to connect to.
* @return The host name.
*/
String hostName() default "";

/**
* The name of queue to connect to.
* @return The name of queue to connect to.
*/
String queueName() default "";

/**
* The username to authenticate with.
* @return The username to authenticate with.
*/
String userName() default "";

/**
* The password to authenticate with.
* @return The password to authenticate with.
*/
String password() default "";

/**
* The port to attach.
* @return The port to attach.
*/
int port() default 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* 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.rabbitmq.annotation;

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

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

/**
* <p>Place this on a parameter whose value would come from RabbitMQ and causing the method to run when a new event arrives.
* The parameter can be one of the following</p>
*
* <ul>
* <li>Any native Java types such as int, String, byte[]</li>
* <li>Any POJO type</li>
* </ul>
*
* <p>The following example is a Java function that uses a RabbitMQ trigger.</p>
*
* <pre>{@literal @}FunctionName("RabbitMQExample")
* public void run(
* {@literal @}@RabbitMQTrigger(
* connectionStringSetting = "ConnectionString",
* queueName = "TestQueue"
* ) String input,
* final ExecutionContext context
* ) {
* context.getLogger().info("Java RabbitMQ trigger processed a request." + input);
* }</pre>
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
@CustomBinding(direction = "in", name = "inputMessage", type = "rabbitMqTrigger")
public @interface RabbitMQTrigger {

/**
* The setting name of connection string.
* @return The connection string setting name from app settings.
*/
String connectionStringSetting() default "";

/**
* The host name to connect to.
* @return The host name.
*/
String hostName() default "";

/**
* The name of queue to connect to.
* @return The name of queue to connect to.
*/
String queueName() default "";

/**
* The username to authenticate with.
* @return The username to authenticate with.
*/
String userNameSetting() default "";

/**
* The password to authenticate with.
* @return The password to authenticate with.
*/
String passwordSetting() default "";

/**
* The port to attach.
* @return The port to attach.
*/
int port() default 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 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.rabbitmq.annotation;

import org.junit.*;
import org.easymock.*;

public class RabbitMQOutputTests {

@Test
public void TestRabbitMQOutput() {
RabbitMQOutput outputInterface = EasyMock.mock(RabbitMQOutput.class);

EasyMock.expect(outputInterface.hostName()).andReturn("randomHostName");
EasyMock.expect(outputInterface.password()).andReturn("randomPassword");
EasyMock.expect(outputInterface.queueName()).andReturn("randomQueueName");
EasyMock.expect(outputInterface.userName()).andReturn("randomUserName");
EasyMock.expect(outputInterface.connectionStringSetting()).andReturn("randomConnectionStringSetting");
EasyMock.expect(outputInterface.port()).andReturn(123);

EasyMock.replay(outputInterface);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 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.rabbitmq.annotation;

import org.junit.*;
import org.easymock.*;

public class RabbitMQTriggerTests {

@Test
public void TestRabbitMQTrigger() {
RabbitMQTrigger triggerInterface = EasyMock.mock(RabbitMQTrigger.class);

EasyMock.expect(triggerInterface.hostName()).andReturn("randomHostName");
EasyMock.expect(triggerInterface.passwordSetting()).andReturn("randomPassword");
EasyMock.expect(triggerInterface.queueName()).andReturn("randomQueueName");
EasyMock.expect(triggerInterface.userNameSetting()).andReturn("randomUserName");
EasyMock.expect(triggerInterface.connectionStringSetting()).andReturn("randomConnectionStringSetting");
EasyMock.expect(triggerInterface.port()).andReturn(123);

EasyMock.replay(triggerInterface);
}

}