简体   繁体   English

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

[英]How to Catch Message Through IronMQ in java

I am trying to fetch some message from IronMQ as well as put some message there through Java program. 我正在尝试从IronMQ中获取一些消息,以及通过Java程序在其中放置一些消息。 I have written the following code but I get a exception, please help. 我已经编写了以下代码,但出现异常,请帮忙。

Thanks in Advance: 提前致谢:

 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();
        }





    }


} 

The exception I get is 我得到的例外是

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();
        }
    }


}

It works for me and i get my messages from IronMq into java 它对我有用,我将IronMq的消息输入Java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM