Java Maven kullanarak hazırlayacağımız projede Eclipse için M2E eklentisini kurmamız gerekiyor. Daha sonra pom.xml dosyasına şunları ekleyeceğiz:
<dependency> <groupId>com.rabbitmq</groupId> <artifactId>amqp-client</artifactId> <version>3.0.4</version> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency>
Endpoint.js
package com.marmelatbilisim.rabbitmq; import java.io.IOException; import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; import com.rabbitmq.client.ConnectionFactory; public abstract class EndPoint { protected Channel channel; protected Connection connection; protected String endPointName; public EndPoint(String endpointName) throws IOException { this.endPointName = endpointName; // Create a connection factory ConnectionFactory factory = new ConnectionFactory(); // hostname of your rabbitmq server factory.setHost("localhost"); // getting a connection connection = factory.newConnection(); // creating a channel channel = connection.createChannel(); // declaring a queue for this channel. If queue does not exist, // it will be created on the server. channel.queueDeclare(endpointName, false, false, false, null); } /** * Close channel and connection. Not necessary as it happens implicitly any * way. * * @throws IOException */ public void close() throws IOException { this.channel.close(); this.connection.close(); } }
Producer.js
package com.marmelatbilisim.rabbitmq; import java.io.IOException; import java.io.Serializable; import org.apache.commons.lang.SerializationUtils; public class Producer extends EndPoint { public Producer(String endPointName) throws IOException { super(endPointName); } public void sendMessage(Serializable object) throws IOException { channel.basicPublish("", endPointName, null, SerializationUtils.serialize(object)); } }
QueueConsumer.js
package com.marmelatbilisim.rabbitmq; import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.apache.commons.lang.SerializationUtils; import com.rabbitmq.client.BasicProperties; import com.rabbitmq.client.Consumer; import com.rabbitmq.client.Envelope; import com.rabbitmq.client.ShutdownSignalException; public class QueueConsumer extends EndPoint implements Runnable, Consumer { public QueueConsumer(String endPointName) throws IOException { super(endPointName); } public void run() { try { // start consuming messages. Auto acknowledge messages. channel.basicConsume(endPointName, true, this); } catch (IOException e) { e.printStackTrace(); } } /** * Called when consumer is registered. */ public void handleConsumeOk(String consumerTag) { System.out.println("Consumer " + consumerTag + " registered"); } /** * Called when new message is available. */ public void handleDelivery(String consumerTag, Envelope env, BasicProperties props, byte[] body) throws IOException { Map map = (HashMap) SerializationUtils.deserialize(body); System.out.println("Message Number " + map.get("message number") + " received."); } public void handleCancel(String consumerTag) { } public void handleCancelOk(String consumerTag) { } public void handleRecoverOk(String consumerTag) { } public void handleShutdownSignal(String consumerTag, ShutdownSignalException arg1) { } public void handleDelivery(String arg0, Envelope arg1, com.rabbitmq.client.AMQP.BasicProperties arg2, byte[] arg3) throws IOException { // TODO Auto-generated method stub } }
Main.js
package com.marmelatbilisim.rabbitmq; import java.io.IOException; import java.sql.SQLException; import java.util.HashMap; public class Main { public Main() throws Exception { QueueConsumer consumer = new QueueConsumer("queue"); Thread consumerThread = new Thread(consumer); consumerThread.start(); Producer producer = new Producer("queue"); for (int i = 0; i < 100000; i++) { HashMap message = new HashMap(); message.put("message number", i); producer.sendMessage(message); System.out.println("Message Number " + i + " sent."); } } /** * @param args * @throws SQLException * @throws IOException */ public static void main(String[] args) throws Exception { new Main(); } }
Bunları hazırladıktan sonra projeye sağ tıklayıp, Run As dedikten sonra Maven Build seçeneğini seçip, Goal olarak clean install bilgilerini girin. Build işlemi bittikten sonra tekrar projeye sağ tıklayıp, Run As dedikten sonra Java Application seçeneğini seçin.
Pingback: 3D Black and gray tattoo Khao Lak
Pingback: Spokane Property Listings
Pingback: nembutal kaufen seriös
Pingback: psilocybin Store uk
Pingback: nagaqq
Pingback: นำเข้าสินค้าจากจีน
Pingback: slot
Pingback: บุหรี่นอก
Pingback: รับทำ SEO
Pingback: 789 คาสิโน
Pingback: cz kadet
Pingback: 토렌트 사이트
Pingback: ขายบ้านพัทยา
Pingback: mejaqq
Pingback: https://zsp2.net/
Pingback: RFID Warehouse Management
Pingback: yehyeh.com
Pingback: click here
Pingback: สล็อตเว็บนอก
Pingback: superkaya88
Pingback: ข่าวบอล
Pingback: web
Pingback: führerschein kaufen online
Pingback: slotjili
Pingback: เว็บหวยออนไลน์
Pingback: lsm99
Pingback: ทำกล่องเค้ก
Pingback: ข่าวบอล
Pingback: วิเคราะห์บอลวันนี้
Pingback: 웹툰 다시보기
Pingback: evoplay ค่ายเกมสล็อตแตกง่าย จ่ายหนัก
Pingback: Seal Private Server
Pingback: ประตู wpc
Pingback: spin 238
Pingback: microdose mushrooms for sale usa
Pingback: Cannabis delivery Toronto
Pingback: ทดลองเล่นสล็อต pp
Pingback: site
Pingback: รับจดทะเบียนสมรสกับชาวต่างชาติ
Pingback: adult shop
Pingback: คาสิโนสด Motivation gaming
Pingback: บริการส่ง SMS