use of com.rabbitmq.client.ConnectionFactory in project zipkin by openzipkin.
the class ITRabbitMQCollector method setup.
@BeforeEach
void setup() throws Exception {
metrics.clear();
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(rabbit.host());
factory.setPort(rabbit.port());
connection = factory.newConnection();
}
use of com.rabbitmq.client.ConnectionFactory in project yacy_grid_mcp by yacy.
the class RabbitQueueFactory method init.
private void init() throws IOException {
ConnectionFactory factory = new ConnectionFactory();
factory.setAutomaticRecoveryEnabled(true);
factory.setHost(this.server);
if (this.port > 0)
factory.setPort(this.port);
if (this.username != null && this.username.length() > 0)
factory.setUsername(this.username);
if (this.password != null && this.password.length() > 0)
factory.setPassword(this.password);
try {
this.connection = factory.newConnection();
// Map<String, Object> map = this.connection.getServerProperties();
if (!this.connection.isOpen())
throw new IOException("no connection");
this.channel = connection.createChannel();
if (!this.channel.isOpen())
throw new IOException("no channel");
this.queues = new ConcurrentHashMap<>();
} catch (TimeoutException e) {
throw new IOException(e.getMessage());
}
}
use of com.rabbitmq.client.ConnectionFactory in project tech by ffyyhh995511.
the class MQServer method getConnection.
public static Connection getConnection() throws Exception {
if (factory == null) {
factory = new ConnectionFactory();
}
factory.setHost(org.tech.commons.util.PropertiesUtil.getProperties("rabbitmq.properties", "mqHost"));
factory.setPort(Integer.parseInt(PropertiesUtil.getProperties("rabbitmq.properties", "mqPort")));
factory.setUsername(PropertiesUtil.getProperties("rabbitmq.properties", "mqUsername"));
factory.setPassword(PropertiesUtil.getProperties("rabbitmq.properties", "mqPassword"));
// virtualHost 可以理解是命名空间
factory.setVirtualHost(PropertiesUtil.getProperties("rabbitmq.properties", "virtualHost"));
Connection connection = factory.newConnection();
return connection;
}
use of com.rabbitmq.client.ConnectionFactory in project tech by ffyyhh995511.
the class Send method main.
public static void main(String[] argv) throws java.io.IOException, TimeoutException, InterruptedException {
System.out.println("----------main method is begin----------");
// 创建工厂
ConnectionFactory factory = new ConnectionFactory();
System.out.println("----------factory successful!----------");
// 设置IP,端口,账户和密码
factory.setHost("127.0.0.1");
factory.setPort(5672);
// factory.setUsername("mq");
// factory.setPassword("mq");
// 创建连接对象
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
System.out.println("----------connected successful!----------");
// 指定队列持久化
channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
String message = getMessage(argv);
// 共发送10万条数据,每隔1S发送1次
int index = 0;
while (index < 100000) {
Thread.sleep(1 * 100);
channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
System.out.println(" [x] Sent '" + message + "'");
index++;
}
channel.close();
connection.close();
}
use of com.rabbitmq.client.ConnectionFactory in project tech by ffyyhh995511.
the class EmitLog method main.
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();
}
Aggregations