如何在java中通过IronMQ捕获消息

时间:2016-06-07 11:03:16

标签: java jms ironmq

我正在尝试从IronMQ获取一些消息,并通过Java程序发送一些消息。 我写了以下代码,但是我得到了一个例外,请帮忙。

提前致谢:

 package com.iron;

import java.io.IOException;
import java.util.Map;

import io.iron.ironmq.Client;
import io.iron.ironmq.Message;
import io.iron.ironmq.Queue;
import io.iron.ironmq.Cloud;

public class Test {

    public static void main(String[] args) 
    {
        String ProjectId;
        String ProjectToken;
        ProjectId="actual ID in String";
        ProjectToken="Project token in string";
        Map<String,String> env=System.getenv();
        Client client = new Client(env.get(ProjectId), env.get(ProjectToken), Cloud.ironAWSUSEast); 
        Queue queue = client.queue("my_queue");
        try 
        {
            queue.push("hello world!");
            Message msg = queue.get();
            System.out.println(msg.getBody());
        } 
        catch (IOException e) 
        {
            e.printStackTrace();
        }





    }


} 

我得到的例外是

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gson/JsonSyntaxException
    at com.iron.Test.main(Test.java:20)`
Caused by: java.lang.ClassNotFoundException: com.google.gson.JsonSyntaxException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

1 个答案:

答案 0 :(得分:0)

import io.iron.ironmq.Client;

import io.iron.ironmq.Cloud;
import io.iron.ironmq.Message;
import io.iron.ironmq.Queue;

public class IronMqTest5 {

    public static void main(String[] args) 
    {
        String projectId="54567889000c707";
        String token="3b3u7uwjwjj8726QZ9CO";
        String scheme="https";
        String host="mq-aws-us-east-1-2.iron.io";
        int port=443;
        try
        {
            Client c = new Client(projectId, token, new Cloud(scheme, host,port));
            //Client c = new Client(projectId, token, new Cloud("http", "localhost", 8080), apiVersion); //this is speified on the github doc but not working here
            Queue q = c.queue("ESIResponse");
            Message msg=q.get();
            System.out.println(msg.getBody());

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }


}

它适用于我,我将来自IronMq的消息发送到java