Skip to content

Commit

Permalink
Merge pull request #30 from Azure/dev
Browse files Browse the repository at this point in the history
Merge latest to master
  • Loading branch information
jtaubensee committed Apr 4, 2017
2 parents d3b107d + 6af6eb8 commit 9553f2e
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 28 deletions.
11 changes: 9 additions & 2 deletions azure-servicebus-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-servicebus-parent</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>1.0.0-PREVIEW</version>
</parent>
<build>
<plugins>
Expand All @@ -27,12 +27,19 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-servicebus</artifactId>
<version>${client-current-version}</version>
<version>1.0.0-PREVIEW</version>
</dependency>
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>proton-j</artifactId>
<version>0.13.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>commicrosoftazure-1653</id>
<name>commicrosoftazure-1653</name>
<url>https://oss.sonatype.org/content/repositories/commicrosoftazure-1653/content/</url>
</repository>
</repositories>
</project>
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package com.microsoft.azure.servicebus.samples;

import java.time.Duration;
import java.util.concurrent.CompletableFuture;

import com.microsoft.azure.servicebus.ClientFactory;
import com.microsoft.azure.servicebus.ExceptionPhase;
import com.microsoft.azure.servicebus.IMessage;
import com.microsoft.azure.servicebus.IMessageHandler;
import com.microsoft.azure.servicebus.IMessageReceiver;
import com.microsoft.azure.servicebus.MessageHandlerOptions;
import com.microsoft.azure.servicebus.QueueClient;
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;
private static QueueClient queueClient;

public static void main(String[] args) throws Exception {
System.out.println("Begining receive sample.");
Expand All @@ -23,19 +27,27 @@ public static void main(String[] args) throws Exception {
throw new Exception("Could not read environment variable: " + ENVIRONMENT_VARIABLE_NAME);
}

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

QueueClient queueClient = new QueueClient(envVar, ReceiveMode.PeekLock);
receiveMessages();
Thread.sleep(60 * 1000);
queueClient.close();
System.out.println("Receive sample completed.");
}

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

@Override
public CompletableFuture<Void> onMessageAsync(IMessage message) {
System.out.println(new String(message.getContent()));
return CompletableFuture.completedFuture(null);
}

@Override
public void notifyException(Throwable exception, ExceptionPhase phase) {
System.out.println(phase + " encountered exception:" + exception.getMessage());
}
}, new MessageHandlerOptions(1, true, Duration.ofMinutes(2)));
}

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

import com.microsoft.azure.servicebus.Message;
import com.microsoft.azure.servicebus.ClientFactory;
import com.microsoft.azure.servicebus.QueueClient;
import com.microsoft.azure.servicebus.ReceiveMode;
import com.microsoft.azure.servicebus.IMessageSender;
import com.microsoft.azure.servicebus.primitives.ConnectionStringBuilder;
import com.microsoft.azure.servicebus.primitives.ServiceBusException;
Expand All @@ -10,7 +11,7 @@ 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;
private static QueueClient queueClient;

public static void main(String[] args) throws Exception {
System.out.println("Begining send sample.");
Expand All @@ -19,20 +20,20 @@ public static void main(String[] args) throws Exception {

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

ConnectionStringBuilder csb = new ConnectionStringBuilder(envVar);
sender = ClientFactory.createMessageSenderFromConnectionStringBuilder(csb);
QueueClient queueClient = new QueueClient(envVar, ReceiveMode.PeekLock);

sendMessages(NUMBER_OF_MESSAGES);
queueClient.close();
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;
Message message = new Message(messageBody.getBytes());
sender.send(message);
queueClient.send(message);
System.out.println("Sending message " + i);
}
}
Expand Down
2 changes: 1 addition & 1 deletion azure-servicebus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-servicebus-parent</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>1.0.0-PREVIEW</version>
</parent>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public SessionHandlerOptions()

/**
*
* @param maxConcurrentCalls
* @param maxConcurrentSessions
* @param autoComplete
* @param maxAutoRenewDuration - Maximum duration within which the client keeps renewing the session lock if the processing of the session messages or onclose action
* is not completed by the handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

/**
* Authorization failed exception is thrown when error is encountered during authorizing user's permission to run the intended operations.
* When encountered this exception user should check whether the token/key provided in the connection string (e.g. one passed to
* {@link EventHubClient#createFromConnectionStringAsync(String)}) is valid, and has correct execution right for the intended operations (e.g.
* Receive call will need Listen claim associated with the key/token).
* When encountered this exception user should check whether the token/key provided in the connection string is valid, and has correct
* execution right for the intended operations (e.g. Receive call will need Listen claim associated with the key/token).
* @see <a href="http://go.microsoft.com/fwlink/?LinkId=761101">http://go.microsoft.com/fwlink/?LinkId=761101</a>
*/
public class AuthorizationFailedException extends ServiceBusException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private ConnectionStringBuilder(
}

/**
* Build a connection string consumable by {@link EventHubClient#createFromConnectionStringAsync(String)}
* Build a connection string
* @param namespaceName Namespace name (dns suffix - ex: .servicebus.windows.net is not required)
* @param entityPath Entity path. For eventHubs case specify - eventHub name.
* @param sharedAccessKeyName Shared Access Key name
Expand All @@ -123,7 +123,7 @@ public ConnectionStringBuilder(


/**
* Build a connection string consumable by {@link EventHubClient#createFromConnectionStringAsync(String)}
* Build a connection string
* @param endpointAddress namespace level endpoint. This needs to be in the format of scheme://fullyQualifiedServiceBusNamespaceEndpointName
* @param entityPath Entity path. For eventHubs case specify - eventHub name.
* @param sharedAccessKeyName Shared Access Key name
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-servicebus-parent</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>1.0.0-PREVIEW</version>
<packaging>pom</packaging>

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

<properties>
<proton-j-version>0.13.1</proton-j-version>
<junit-version>4.12</junit-version>
<client-current-version>0.1.0-SNAPSHOT</client-current-version>
<client-current-version>1.0.0-PREVIEW</client-current-version>
</properties>

<modules>
Expand Down

0 comments on commit 9553f2e

Please sign in to comment.