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

How to Catch Message Through IronMQ in java

我正在尝试从 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