如何在java中通过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)
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 中

相关内容

  • 没有找到相关文章