How to Receive a Notification from IBM MQ Light

Java SDK

import static com.ibm.mqlight.api.Delivery.Type.STRING;
import static java.lang.System.out;

import com.ibm.mqlight.api.ClientOptions;
import com.ibm.mqlight.api.Delivery;
import com.ibm.mqlight.api.DestinationAdapter;
import com.ibm.mqlight.api.NonBlockingClient;
import com.ibm.mqlight.api.NonBlockingClientAdapter;
import com.ibm.mqlight.api.StringDelivery;

public final class IbmCloudSample {

  public static void main(final String[] args) {
    NonBlockingClient.create("amqp://host:1912", ClientOptions.builder().setCredentials("username", "password").build(), new NonBlockingClientAdapter<Void>() {

        public void onStarted(final NonBlockingClient client, final Void context) {
          client.subscribe("SampleTopic", new DestinationAdapter<Void>() {

              public void onMessage(final NonBlockingClient client, final Void context, final Delivery delivery) {

                if (delivery.getType() == STRING)
                  out.println(((StringDelivery) delivery).getData());

              }

            }, null, null);
        }

      }, null);
  }

}
Advertisements

How to Send a Notification to IBM MQ Light

Java SDK

import com.ibm.mqlight.api.ClientOptions;
import com.ibm.mqlight.api.NonBlockingClient;
import com.ibm.mqlight.api.NonBlockingClientAdapter;

public final class IbmCloudSample {

  public static void main(final String[] args) {
    NonBlockingClient.create("amqp://host:1912", ClientOptions.builder().setCredentials("username", "password").build(), new NonBlockingClientAdapter<Void>() {

        public void onStarted(final NonBlockingClient client, final Void context) {
          client.send("SampleTopic", "Sample Message", null);
        }

      }, null);
  }

}