All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.devebot.opflow.examples.OpflowPubsubExample Maven / Gradle / Ivy

There is a newer version: 0.1.3
Show newest version
package com.devebot.opflow.examples;

import java.util.HashMap;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.io.IOException;
import com.devebot.opflow.OpflowMessage;
import com.devebot.opflow.OpflowPubsubHandler;
import com.devebot.opflow.OpflowPubsubListener;

/**
 *
 * @author drupalex
 */
public class OpflowPubsubExample {

    public static void main(String[] argv) throws Exception {
        final Gson gson = new Gson();
        final JsonParser jsonParser = new JsonParser();
        final HashMap flowParams = new HashMap();
        flowParams.put("uri", "amqp://master:[email protected]?frameMax=0x1000");
        flowParams.put("exchangeName", "tdd-opflow-publisher");
        flowParams.put("exchangeType", "direct");
        flowParams.put("routingKey", "tdd-opflow-pubsub-public");
        flowParams.put("consumer.queueName", "tdd-opflow-subscriber#5");

        final OpflowPubsubHandler pubsub = new OpflowPubsubHandler(flowParams);
        pubsub.subscribe(new OpflowPubsubListener() {
            @Override
            public void processMessage(OpflowMessage message) throws IOException {
                JsonObject jsonObject = (JsonObject)jsonParser.parse(new String(message.getContent(), "UTF-8"));
                System.out.println(" [+] Received '" + jsonObject.toString() + "'");
            }
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy