本文整理匯總了Java中com.rabbitmq.client.ConnectionFactory.setHost方法的典型用法代碼示例。如果您正苦於以下問題:Java ConnectionFactory.setHost方法的具體用法?Java ConnectionFactory.setHost怎麽用?Java ConnectionFactory.setHost使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.rabbitmq.client.ConnectionFactory
的用法示例。
在下文中一共展示了ConnectionFactory.setHost方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername("guest");
factory.setPassword("guest");
factory.setVirtualHost("/");
factory.setHost("localhost");
factory.setPort(5672);
Connection newConnection = factory.newConnection();
Channel channel = newConnection.createChannel();
Scanner scanner = new Scanner(System.in);
String message = "";
while(!message.equals("exit")){
System.out.println("Enter your message");
message = scanner.next();
channel.queueDeclare("flink-test", true, false, false, null);
channel.basicPublish("", "flink-test", new BasicProperties.Builder()
.correlationId(java.util.UUID.randomUUID().toString()).build(), message.getBytes());
}
scanner.close();
channel.close();
newConnection.close();
}
開發者ID:PacktPublishing,項目名稱:Practical-Real-time-Processing-and-Analytics,代碼行數:26,代碼來源:RMQPublisher.java
示例2: main
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.FANOUT);
String message = getMessage(argv);
channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes("UTF-8"));
System.out.println(" [x] Sent '" + message + "'");
channel.close();
connection.close();
}
示例3: main
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
String message = getMessage(argv);
channel.basicPublish("", TASK_QUEUE_NAME,
MessageProperties.PERSISTENT_TEXT_PLAIN,
message.getBytes("UTF-8"));
System.out.println(" [x] Sent '" + message + "'");
channel.close();
connection.close();
}
示例4: main
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
/**
* @param args
* @throws IOException
* @throws TimeoutException
* @date 2017年7月11日 下午5:53:02
* @writer junehappylove
*/
public static void main(String[] args) throws IOException, TimeoutException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(host);
factory.setUsername(username);
factory.setPassword(password);
factory.setPort(port);
factory.setVirtualHost(virtualHost);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
// 分發信息
for (int i = 0; i < 20; i++) {
String message = "Hello RabbitMQ" + i;
channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
System.out.println("NewTask send '" + message + "'");
}
channel.close();
connection.close();
}
示例5: main
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
/**
* @param args
* @throws TimeoutException
* @throws IOException
* @date 2017年7月13日 下午2:49:49
* @writer junehappylove
*/
public static void main(String[] args) throws IOException, TimeoutException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(host);
factory.setUsername(username);
factory.setPassword(password);
factory.setPort(port);
factory.setVirtualHost(virtualHost);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
// 聲明交換機
channel.exchangeDeclare(EXCHANGE_NAME_ROUTING, "direct");// 注意是direct
// 發送信息
for (String routingKey : routingKeys) {
String message = "RoutingSendDirect Send the message level:" + routingKey;
channel.basicPublish(EXCHANGE_NAME_ROUTING, routingKey, null, message.getBytes());
System.out.println("RoutingSendDirect Send" + routingKey + "':'" + message);
}
channel.close();
connection.close();
}
示例6: main
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
/**
* @param args
* @throws TimeoutException
* @throws IOException
* @date 2017年7月13日 下午2:37:37
* @writer junehappylove
*/
public static void main(String[] args) throws IOException, TimeoutException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(host);
factory.setUsername(username);
factory.setPassword(password);
factory.setPort(port);
factory.setVirtualHost(virtualHost);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare(EXCHANGE_NAME, "fanout");// fanout表示分發,所有的消費者得到同樣的隊列信息
// 分發信息
for (int i = 0; i < 5; i++) {
String message = "Hello World" + i;
channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes());
System.out.println("EmitLog Sent '" + message + "'");
}
channel.close();
connection.close();
}
示例7: consumeWithoutCertificate
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
/**
* Helper method to retrieve queue message from rabbitMQ
*
* @return result
* @throws Exception
*/
private static String consumeWithoutCertificate() throws Exception {
String result = "";
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
factory.setPort(5671);
factory.useSslProtocol();
Connection conn = factory.newConnection();
Channel channel = conn.createChannel();
GetResponse chResponse = channel.basicGet("WithoutClientCertQueue", true);
if(chResponse != null) {
byte[] body = chResponse.getBody();
result = new String(body);
}
channel.close();
conn.close();
return result;
}
開發者ID:wso2,項目名稱:product-ei,代碼行數:26,代碼來源:ESBJAVA4569RabbiMQSSLStoreWithoutClientCertValidationTest.java
示例8: main
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String queueName = "TestQueue";
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("127.0.0.1");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(queueName, false, false, false, null);
System.out.println(" [*] Waiting for messages...");
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(queueName, true, consumer);
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
System.out.println(" [x] Received '" + message + "'");
}
}
示例9: registerFactory
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
/**
* 注冊主機
*
* @param hostPort
*/
private synchronized static void registerFactory(String hostPort) {
if (hostPort == null || hostPort.isEmpty())
return;
if (!hostPort.contains(":"))
return;
String[] params = hostPort.split(":");
if (params.length != 2) {
logger.warn("hostPort illegal, length is not 2");
return;
}
logger.info("registering new factory [" + hostPort + "] ...");
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(params[0]);
factory.setPort(Integer.valueOf(params[1]));
factory.setAutomaticRecoveryEnabled(automaticRecovery);
factory.setNetworkRecoveryInterval(networkRecoveryInterval);
factory.setUsername(userName);
factory.setPassword(password);
ConnectionFactoryManager.getInstance().register(hostPort, factory);
}
示例10: main
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
public static void main(String[] argv) 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();
}
示例11: connectToBroker
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
public void connectToBroker(){
try {
/*Get a ConnectionFactory object */
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(ip);
factory.setPort(port);
factory.setUsername(user);
factory.setPassword(password);
/* Create a connection */
connection = factory.newConnection();
/* Create a channel over that TCP/IP connection */
channel = connection.createChannel();
}
catch(Exception e){
e.printStackTrace();
}
}
示例12: send
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
@POST
@Path("rabbitmqRecv")
public void send() throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername("guest");
factory.setPassword("guest");
factory.setHost("127.0.0.1");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
DefaultConsumer consumer = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
byte[] body) throws IOException {
System.out.println(properties.getHeaders());
String message = new String(body, "UTF-8");
System.out.println(" [x] Received '" + message + "'");
}
};
channel.basicConsume(QUEUE_NAME, true, consumer);
}
示例13: main
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
/**
* @param args
* @throws IOException
* @throws TimeoutException
* @date 2017年7月13日 下午2:57:32
* @writer junehappylove
*/
public static void main(String[] args) throws IOException, TimeoutException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(host);
factory.setUsername(username);
factory.setPassword(password);
factory.setPort(port);
factory.setVirtualHost(virtualHost);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
// 聲明交換器
channel.exchangeDeclare(EXCHANGE_NAME_ROUTING, "direct");
// 獲取匿名隊列名稱
String queueName = channel.queueDeclare().getQueue();
// 根據路由關鍵字進行多重綁定
for (String severity : routingKeys2) {
channel.queueBind(queueName, EXCHANGE_NAME_ROUTING, severity);
System.out.println("ReceiveLogsDirect2 exchange:" + EXCHANGE_NAME_ROUTING + ", queue:" + queueName
+ ", BindRoutingKey:" + severity);
}
System.out.println("ReceiveLogsDirect2 Waiting for messages");
Consumer consumer = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
byte[] body) throws UnsupportedEncodingException {
String message = new String(body, "UTF-8");
System.out.println("ReceiveLogsDirect2 Received '" + envelope.getRoutingKey() + "':'" + message + "'");
}
};
channel.basicConsume(queueName, true, consumer);
}
示例14: main
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
/**
* @param args
* @throws TimeoutException
* @throws IOException
* @date 2017年7月11日 下午5:32:45
* @writer junehappylove
*/
public static void main(String[] args) throws IOException, TimeoutException {
// 創建連接工廠
ConnectionFactory factory = new ConnectionFactory();
// 設置RabbitMQ地址
factory.setHost(host);
factory.setUsername(username);
factory.setPassword(password);
factory.setPort(port);
factory.setVirtualHost(virtualHost);
// 創建一個新的連接
Connection connection = factory.newConnection();
// 創建一個通道
Channel channel = connection.createChannel();
// 聲明要關注的隊列
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println("Customer Waiting Received messages");
// DefaultConsumer類實現了Consumer接口,通過傳入一個頻道,
// 告訴服務器我們需要那個頻道的消息,如果頻道中有消息,就會執行回調函數handleDelivery
Consumer consumer = new DefaultConsumer(channel) {
//envelope主要存放生產者相關信息(比如交換機、路由key等)
//body是消息實體
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
byte[] body) throws IOException {
String message = new String(body, "UTF-8");
System.out.println("Customer Received '" + message + "'");
}
};
// 自動回複隊列應答 -- RabbitMQ中的消息確認機製
channel.basicConsume(QUEUE_NAME, true, consumer);
}
示例15: main
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
/**
* @param args
* @throws TimeoutException
* @throws IOException
* @date 2017年7月13日 下午3:03:24
* @writer junehappylove
*/
public static void main(String[] args) throws IOException, TimeoutException {
Connection connection = null;
Channel channel = null;
try {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(host);
factory.setUsername(username);
factory.setPassword(password);
factory.setPort(port);
factory.setVirtualHost(virtualHost);
connection = factory.newConnection();
channel = connection.createChannel();
// 聲明一個匹配模式的交換機
channel.exchangeDeclare(EXCHANGE_NAME_TOPIC, "topic");
// 待發送的消息
String[] routingKeys = new String[] { "quick.orange.rabbit", "lazy.orange.elephant", "quick.orange.fox",
"lazy.brown.fox", "quick.brown.fox", "quick.orange.male.rabbit", "lazy.orange.male.rabbit" };
// 發送消息
for (String severity : routingKeys) {
String message = "From " + severity + " routingKey' s message!";
channel.basicPublish(EXCHANGE_NAME_TOPIC, severity, null, message.getBytes());
System.out.println("TopicSend Sent '" + severity + "':'" + message + "'");
}
} catch (Exception e) {
e.printStackTrace();
if (connection != null) {
channel.close();
connection.close();
}
} finally {
if (connection != null) {
channel.close();
connection.close();
}
}
}