Skip to content

Commit

Permalink
Java send & receive samples (#2)
Browse files Browse the repository at this point in the history
* Initial commit of samples branch

* Updating readme to include up-to-date roadmap

* Changing folder structure, and adding samples...

* Removing old sample files

* updating readme to be more clear on roadmap

* Updating connection string name

* Copying .gitignore from Azure Java SDk https://github.com/Azure/azure-sdk-for-java/blob/master/.gitignore

* Removing ignored files

* Mistakenly added IllegalEntityException in last merge
  • Loading branch information
banisadr authored and yvgopal committed Feb 2, 2017
1 parent 01f9360 commit 4ac5b6b
Show file tree
Hide file tree
Showing 84 changed files with 195 additions and 104 deletions.
26 changes: 0 additions & 26 deletions .classpath

This file was deleted.

79 changes: 40 additions & 39 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
### Eclipse ###
*.class

#External libs
extlib/

# Auth files
*.auth
*.azureauth

# Local checkstyle
*.checkstyle

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# Azure Tooling #
node_modules
packages

# Eclipse #
*.pydevproject
.project
.metadata
bin/
tmp/
bin/**
tmp/**
tmp/**/*
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
.recommenders

# Eclipse Core
.project

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# JDT-specific (Eclipse Java Development Tools)
# Other Tooling #
.classpath
.project
target
.idea
*.iml

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans
# Mac OS #
.DS_Store
.DS_Store?

# Code Recommenders
.recommenders/
# Windows #
Thumbs.db
23 changes: 0 additions & 23 deletions .project

This file was deleted.

5 changes: 0 additions & 5 deletions .settings/org.eclipse.jdt.core.prefs

This file was deleted.

4 changes: 0 additions & 4 deletions .settings/org.eclipse.m2e.core.prefs

This file was deleted.

37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,39 @@ Refer to [azure.com](https://azure.microsoft.com/services/service-bus/) to learn

## How to provide feedback

See our [Contribution Guidelines](./.github/CONTRIBUTING.md).
See our [Contribution Guidelines](./.github/CONTRIBUTING.md).

## Road map

- [x] Sprint 1: **Complete**

All runtime operations for queues (not topics / subscriptions)
* Send
* Receive/Peeklock (without receive by sequence number)
* Abandon
* Deadletter
* Defer

- [ ] Sprint 2: **Batch operations complete**
* RenewLock (Request/Response)
* ~~Batch operation - Explicit batching only~~
* Runtime operation only
* Linux testing setup/investigation

- [ ] Sprint 3: **Topic/subscription support complete**
* ~~Add topic/subscription support~~
* Session support
* Accept session
* Session Receive/ReceiveBatch

- [ ] Sprint 4: **Retry policy complete**
* ~~Retry policy~~
* Receive by sequence number

- [ ] Sprint 5:
* Add major error conditions (ex. preventing all operations that are not supported, for Ex Transaction scenarios, etc)
* Request/Response features:
* Add/Remove Rule
* Browse messages and sessions
* Scheduled messages specific API (Scheduling of messages can be done today through the queue/topic client, but this item is to add specific API's for scheduled messages)
* OnMessage/OnSession handlers
31 changes: 31 additions & 0 deletions azure-servicebus-samples/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<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>azure-servicebus-samples</groupId>
<artifactId>azure-servicebus-samples</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source/>
<target/>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>proton-j</artifactId>
<version>0.13.1</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.49</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.microsoft.azure.servicebus.samples;

import java.time.Duration;

import com.microsoft.azure.servicebus.ClientFactory;
import com.microsoft.azure.servicebus.IBrokeredMessage;
import com.microsoft.azure.servicebus.IMessageReceiver;
import com.microsoft.azure.servicebus.ReceiveMode;
import com.microsoft.azure.servicebus.primitives.ConnectionStringBuilder;
import com.microsoft.azure.servicebus.primitives.ServiceBusException;

public class ReceiveSample {

private static final String ENVIRONMENT_VARIABLE_NAME = "azure-service-bus-java/connectionstring";
private static IMessageReceiver receiver;

public static void main(String[] args) throws Exception {
System.out.println("Begining receive sample.");

String envVar = System.getenv(ENVIRONMENT_VARIABLE_NAME);

if (envVar.isEmpty()) {
throw new Exception("Could not read environment variable: " + ENVIRONMENT_VARIABLE_NAME);
}

ConnectionStringBuilder csb = new ConnectionStringBuilder(envVar);
receiver = ClientFactory.createMessageReceiverFromConnectionStringBuilder(csb, ReceiveMode.PeekLock);

receiveMessages();
System.out.println("Receive sample completed.");
}

private static void receiveMessages() throws InterruptedException, ServiceBusException {
while (true) {
IBrokeredMessage receivedMessage = receiver.receive(Duration.ofMinutes(1));
System.out.println(new String(receivedMessage.getContent()));
receiver.complete(receivedMessage);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.microsoft.azure.servicebus.samples;

import com.microsoft.azure.servicebus.BrokeredMessage;
import com.microsoft.azure.servicebus.ClientFactory;
import com.microsoft.azure.servicebus.IMessageSender;
import com.microsoft.azure.servicebus.primitives.ConnectionStringBuilder;
import com.microsoft.azure.servicebus.primitives.ServiceBusException;

public class SendSample {

private static final String ENVIRONMENT_VARIABLE_NAME = "azure-service-bus-java/connectionstring";
private static final int NUMBER_OF_MESSAGES = 1;
private static IMessageSender sender;

public static void main(String[] args) throws Exception {
System.out.println("Begining send sample.");

String envVar = System.getenv(ENVIRONMENT_VARIABLE_NAME);

if (envVar.isEmpty()) {
throw new Exception("Could not read environment variable: " + ENVIRONMENT_VARIABLE_NAME);
}

ConnectionStringBuilder csb = new ConnectionStringBuilder(envVar);
sender = ClientFactory.createMessageSenderFromConnectionStringBuilder(csb);

sendMessages(NUMBER_OF_MESSAGES);
System.out.println("Send sample completed.");
}

private static void sendMessages(int numMessages) throws InterruptedException, ServiceBusException {
for(int i = 0; i < numMessages; i ++) {
String messageBody = "MessageNumber: " + i;
BrokeredMessage message = new BrokeredMessage(messageBody.getBytes());
sender.send(message);
System.out.println("Sending message " + i);
}
}
}
8 changes: 4 additions & 4 deletions pom.xml → azure-servicebus/pom.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<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">

<description>Java libraries for talking to Windows Azure Service Bus</description>
<description>Java library for Azure Service Bus</description>

<modelVersion>4.0.0</modelVersion>

<groupId>com.microsoft.azure</groupId>
<artifactId>azure-messaging-java-clients</artifactId>
<artifactId>azure-servicebus</artifactId>
<version>${client-current-version}</version>

<url>https://github.com/Azure/azure-messaging-java</url>
<url>https://github.com/Azure/azure-service-bus-java</url>

<properties>
<proton-j-version>0.13.1</proton-j-version>
Expand Down Expand Up @@ -51,5 +51,5 @@
<scope>test</scope>
</dependency>
</dependencies>
<name>azure-messaging-java-clients</name>
<name>azure-servicebus</name>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ public void onReceiveComplete(Delivery delivery)
String deliveryTagAsString = StringUtil.convertBytesToString(delivery.getTag());
if(deliveryTag == null || deliveryTag.length == 0 || !this.tagsToDeliveriesMap.containsKey(deliveryTagAsString))
{
System.out.println("new-" + Util.convertDotNetBytesToUUID(delivery.getTag()));
Message message = null;

int msgSize = delivery.pending();
Expand Down Expand Up @@ -450,7 +449,6 @@ public void onReceiveComplete(Delivery delivery)
}
else
{
System.out.println("old-" + Util.convertDotNetBytesToUUID(delivery.getTag()));
DeliveryState remoteState = delivery.getRemoteState();
if(remoteState instanceof Outcome)
{
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions azure-servicebus/test/access.properties.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespacename=yournamespace
entitypath=yourentitypath
sharedaccesskeyname=yoursharedaccesskey
sharedaccesskey=yoursharedaccesskey

0 comments on commit 4ac5b6b

Please sign in to comment.