简体   繁体   中英

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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