How to Receive a Notification from the Microsoft Azure Service Bus with Java

import static java.lang.System.out;

import com.microsoft.windowsazure.services.servicebus.ServiceBusConfiguration;
import com.microsoft.windowsazure.services.servicebus.ServiceBusContract;
import com.microsoft.windowsazure.services.servicebus.ServiceBusService;
import com.microsoft.windowsazure.services.servicebus.models.BrokeredMessage;
import com.microsoft.windowsazure.services.servicebus.models.ReceiveSubscriptionMessageResult;

public final class AzureSample {

  public static void main(final String[] args) throws Exception {
    final ServiceBusContract service = ServiceBusService.create(ServiceBusConfiguration.configureWithSASAuthentication("accountname", "sharedaccesskeyname", "sharedaccesskey", ".servicebus.windows.net"));

    final ReceiveSubscriptionMessageResult res = service.receiveSubscriptionMessage("SampleTopic", "SampleSubscription");

    final BrokeredMessage msg = res.getValue();

    out.println(msg);
  }

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s