如何通过JAVA在IronMQ中推送消息

时间:2016-06-08 06:50:27

标签: java jms spring-jms ironmq

我试图通过JAVA程序在IronMQ中推送一些消息, 我写了下面的代码,但我遇到了一个Exception请帮助, 在此先感谢:

 package com.iron;
    import java.io.IOException;

    import io.iron.ironmq.*;

    import org.junit.Assert;
    import org.junit.Assume;
    import org.junit.Before;
    import org.junit.Test;


    public class IronMQTest 
    {
        private String projectId;
        private String token;
        @Before public void setup() 
        {
            projectId = System.getenv("57123456de900078dc707");
            token = System.getenv("3b3DmQg0hc58963245O");
            Assume.assumeTrue(projectId != null && token != null);
        }

        @Test public void testClient() throws IOException {
            Client c = new Client(projectId, token, Cloud.ironAWSUSEast);
            Queue q = c.queue("test-queue");

            // clear out the queue
            try {
                while (true) {
                    Message msg = q.get();
                    q.deleteMessage(msg);
                }
            } catch (EmptyQueueException e) {
            }

            final String body = "Hello, IronMQ!";

            String id = q.push(body);

            Message msg = q.get();
            Assert.assertEquals(body, msg.getBody());
            Assert.assertEquals(id, msg.getId());
            q.deleteMessage(msg);
        }

        @Test(expected=HTTPException.class) public void testErrorResponse() throws IOException {
            // intentionally invalid project/token combination
            Client c = new Client("4444444444444", "aaaaaa", Cloud.ironAWSUSEast);
            Queue q = c.queue("test-queue");

            q.push("test");
        }


    }

我调用所有上述方法的主文件

package com.iron;

public class IronMain {

    public static void main(String[] args) 
    {
        try
        {
            IronMQTest iq = new IronMQTest();
            iq.setup();
            iq.testClient();
            iq.testErrorResponse();

        }

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

}

例外:

Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    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)
    at com.iron.IronMQTest.setup(IronMQTest.java:20)
    at com.iron.IronMain.main(IronMain.java:10)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
    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)
    ... 14 more

0 个答案:

没有答案