Örnek

Active MQ Artemis Producer Örneği

Bu örnekte ActiveMQ Armetis'de bir mesaj üretip kuyruğa ekliyoruz. ActiveMQ Artmesin için aşağıdaki Maven tanımı eklenir:
<dependency>
	<groupId>org.apache.activemq</groupId>
	<artifactId>artemis-jms-client</artifactId>
	<version>2.6.3</version>
</dependency>
Mesaj aşağıdaki uygulama ile test edilebilir:
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.jms.client.ActiveMQQueue;

public class ArtemisProducerTest {

public static void main(String[] args) {
	Connection connection = null;
	Session session = null;

	try {

		ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://activemqtest.fibiler.com:1234");

		connection = cf.createConnection();

		session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

		Queue activeMQQueue=new ActiveMQQueue("queue.FIBILER","TESTQUE"); 
		//ActiveMQQueue activeMQQueue=new ActiveMQQueue("queue.FIBILER::TESTQUE");
		
		MessageProducer messageProducer1 = session.createProducer(activeMQQueue);
		MessageProducer messageProducer2 = session.createProducer(activeMQQueue);
		
		Message msg = session.createTextMessage("Test Mesaji 1");
		
		messageProducer1.send(msg);
		messageProducer2.send(msg);

		System.out.println("Send Mesaj...");		
		
	} catch (JMSException e) {
		e.printStackTrace();
	} finally {
		if (session != null) {
			try {
				session.close();
			} catch (JMSException e) {
				e.printStackTrace();
			}
		}
		if (connection != null) {
			try {
				connection.close();
			} catch (JMSException e) {
				e.printStackTrace();
			}
		}
	}
}
}
Factory olarak ActiveMQConnectionFactory sınıfını kullanıyoruz. Connection ve Session yaratma JMS standarlarına göre yapılır. Kuyruk olarak ActiveMQQueue sınıfı kullanılmalıdır. Bu sınıf bir adres bir de kuyruk adı almaktadır. Ardından iki tane prodecur yaratılır ve mesajlar eklenir.
zafer.teker , 07.03.2020

Bu Sayfayı Paylaş:

Fibiler Üyelerinin Yorumları


Tüm üyeler içeriklere yorum ekleyerek katkıda bulunabilir : Yorum Gir

Misafir Yorumları




Bu Sayfayı Paylaş:

İletişim Bilgileri

Takip Et

Her Hakkı Saklıdır. Bu sitede yayınlanan tüm bilgi ve fikirlerin kullanımından fibiler.com sorumlu değildir. Bu sitede üretilmiş , derlenmiş içerikleri, fibiler.com'u kaynak göstermek koşuluyla kendi sitenizde kullanılabilirsiniz. Ancak telif hakkı olan içeriklerin hakları sahiplerine aittir