import org.queuj.AbstractJob; import org.queuj.ProcessingException; import org.queuj.Queue; public class MyJob extends AbstractJob { @Override public void process() throws ProcessingException { } public static void main(String[] args) throws Exception { Queue queue = QueueFactory.getQueue("myQueue"); AbstractJob job = new MyJob(); queue.enqueue(job); } } import com.rabbitmq.client.ConnectionFactory; import com.rabbitmq.client.Connection; import com.rabbitmq.client.Channel; public class Producer { private final static String QUEUE_NAME = "myQueue"; public static void main(String[] args) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); String message = "Hello World!"; channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8")); System.out.println(" [x] Sent '" + message + "'"); channel.close(); connection.close(); } }


上一篇:
下一篇:
切换中文