super.setPort(this.port); super.setUsername(this.username); super.setPassword(this.password);
public void connect() throws IOException { final ConnectionFactory factory = new ConnectionFactory(); factory.setHost(hostname); factory.setPort(port); factory.setVirtualHost(virtualHost); factory.setRequestedHeartbeat(heartbeatTimeout);
factory.setPort(this.port); factory.setVirtualHost(this.virtualHost); factory.setUsername(this.username);
protected Connection createConnection(ProcessContext context) { final ConnectionFactory cf = new ConnectionFactory(); cf.setHost(context.getProperty(HOST).evaluateAttributeExpressions().getValue()); cf.setPort(Integer.parseInt(context.getProperty(PORT).evaluateAttributeExpressions().getValue())); cf.setUsername(context.getProperty(USER).evaluateAttributeExpressions().getValue()); cf.setPassword(context.getProperty(PASSWORD).getValue());
public RabbitmqProducer(MaxwellContext context) { super(context); exchangeName = context.getConfig().rabbitmqExchange; props = context.getConfig().rabbitmqMessagePersistent ? MessageProperties.MINIMAL_PERSISTENT_BASIC : null; ConnectionFactory factory = new ConnectionFactory(); factory.setHost(context.getConfig().rabbitmqHost); factory.setPort(context.getConfig().rabbitmqPort); factory.setUsername(context.getConfig().rabbitmqUser); factory.setPassword(context.getConfig().rabbitmqPass); factory.setVirtualHost(context.getConfig().rabbitmqVirtualHost); try { this.channel = factory.newConnection().createChannel(); if(context.getConfig().rabbitmqDeclareExchange) { this.channel.exchangeDeclare(exchangeName, context.getConfig().rabbitmqExchangeType, context.getConfig().rabbitMqExchangeDurable, context.getConfig().rabbitMqExchangeAutoDelete, null); } } catch (IOException | TimeoutException e) { throw new RuntimeException(e); } }
@Test public void simpleRabbitMqTest() throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(rabbitMq.getContainerIpAddress()); factory.setPort(rabbitMq.getMappedPort(RABBITMQ_PORT)); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(RABBIQMQ_TEST_EXCHANGE, "direct", true); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, RABBIQMQ_TEST_EXCHANGE, RABBITMQ_TEST_ROUTING_KEY); // Set up a consumer on the queue final boolean[] messageWasReceived = new boolean[1]; channel.basicConsume(queueName, false, new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { messageWasReceived[0] = Arrays.equals(body, RABBITMQ_TEST_MESSAGE.getBytes()); } }); // post a message channel.basicPublish(RABBIQMQ_TEST_EXCHANGE, RABBITMQ_TEST_ROUTING_KEY, null, RABBITMQ_TEST_MESSAGE.getBytes()); // check the message was received assertTrue("The message was received", Unreliables.retryUntilSuccess(5, TimeUnit.SECONDS, () -> { if (!messageWasReceived[0]) { throw new IllegalStateException("Message not received yet"); } return true; })); }
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()); } }
public static void main(String[] args) { try { ConnectionFactory factory = new ConnectionFactory(); factory.setUsername("guest"); factory.setPassword("guest"); factory.setHost("60.205.191.82"); factory.setPort(5672); Connection conn = factory.newConnection(); Channel channel = conn.createChannel(); // channel.qu channel.queueDeclare("hello", false, false, false, null); String message = "Hello World!"; channel.basicPublish("", "hello", null, message.getBytes()); System.out.println(" [x] Sent '" + message + "'"); channel.close(); conn.close(); } catch (IOException e) { e.printStackTrace(); } catch (TimeoutException e) { e.printStackTrace(); } } }
/** * Set the port. */ public ConnectionOptions withPort(int port) { factory.setPort(port); return this; }
/** * @param port the port. * @see com.rabbitmq.client.ConnectionFactory#setPort(int) */ public void setPort(int port) { this.connectionFactory.setPort(port); }
/** * Set the port. */ public ConnectionOptions withPort(int port) { factory.setPort(port); return this; }
/** * @param port the port. * @see com.rabbitmq.client.ConnectionFactory#setPort(int) */ public void setPort(int port) { this.connectionFactory.setPort(port); }
@Bean public ConnectionFactory connectionFactory() throws Exception { ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setHost(env.getProperty("mq.host").trim()); connectionFactory.setPort(Integer.parseInt(env.getProperty("mq.port").trim())); connectionFactory.setVirtualHost(env.getProperty("mq.vhost").trim()); connectionFactory.setUsername(env.getProperty("mq.username").trim()); connectionFactory.setPassword(env.getProperty("mq.password").trim()); return connectionFactory; }
/** * @param props RabbitMQ 配置信息 */ public RabbitMQClusterPolicy(Properties props){ this.exchange = props.getProperty("exchange", "j2cache"); factory = new ConnectionFactory(); factory.setHost(props.getProperty("host" , "127.0.0.1")); factory.setPort(Integer.valueOf(props.getProperty("port", "5672"))); factory.setUsername(props.getProperty("username" , null)); factory.setPassword(props.getProperty("password" , null)); //TODO 更多的 RabbitMQ 配置 }
public static Channel connect() throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("193.163.91.102"); factory.setPort(32768); Connection conn = factory.newConnection(); return conn.createChannel(); }
/** * Sets the ConnectionFactory parameters */ private void setFactoryConfiguration() { factory.setHost(this.host); factory.setPort(this.port); factory.setVirtualHost(this.virtualHost); factory.setUsername(this.username); factory.setPassword(this.password); }
public FirstMsgSender(String host, int port, String queueName) throws IOException, TimeoutException { super(); factory.setHost(host); factory.setPort(port); connection = factory.newConnection(); channel = connection.createChannel(); channel.queueDeclare(queueName, true, false, false, null); this.queueName = queueName; }
public MQClient(String host, int port, String queue_name) throws IOException, TimeoutException { factory.setHost(host); factory.setPort(port); this.queueName = queue_name; connection = factory.newConnection(); channel = connection.createChannel(); channel.queueDeclare(queue_name, true, false, false, null); } }
protected ConnectionFactory createFactory(Properties properties) { LOG.debug("Creating RabbitMQ connection factory with properties: {}", properties); ConnectionFactory factory = new ConnectionFactory(); factory.setUsername(USERNAME.readFrom(properties)); factory.setPassword(PASSWORD.readFrom(properties)); factory.setVirtualHost(VIRTUAL_HOST.readFrom(properties)); factory.setHost(HOST.readFrom(properties)); factory.setPort(Integer.parseInt(PORT.readFrom(properties))); factory.setExceptionHandler(handleChannelExceptions()); return factory; }
public ConnectionFactory connectionFactory() { ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setHost(getHostIp()); connectionFactory.setPort(getPort()); connectionFactory.setUsername(getUsername()); connectionFactory.setPassword(getPassword()); return connectionFactory; }