public void connect() throws IOException { final ConnectionFactory factory = new ConnectionFactory(); factory.setHost(hostname); factory.setPort(port);
ConnectionFactory factory = new ConnectionFactory(); if (this.uri != null && !this.uri.isEmpty()){ try {
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()));
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; })); }
ConnectionFactory factory = new ConnectionFactory(); Connection connection = null ; try {
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()); } }
ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); //**The threads part is as follows** channel.exchangeDeclare(EXCHANGE_NAME, "direct"); String queueName = channel.queueDeclare().getQueue(); // This part will biend the queue with the severity (login for eg:) for(String severity : argv){ channel.queueBind(queueName, EXCHANGE_NAME, routingKey); } boolean autoAck = false; channel.basicConsume(queueName, autoAck, "myConsumerTag", new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String routingKey = envelope.getRoutingKey(); String contentType = properties.contentType; long deliveryTag = envelope.getDeliveryTag(); // (process the message components here ...) channel.basicAck(deliveryTag, false); } });
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(); } } }
void init() { try { ConnectionFactory connFactory = new ConnectionFactory(); List<Address> addresses = CollectionUtils.transformToList(bus.getServerIps(), new Function<Address, String>() { @Override public Address call(String arg) { return Address.parseAddress(arg); } }); conn = connFactory.newConnection(addresses.toArray(new Address[]{})); chan = conn.createChannel(); String name = MessageTracker.class.getName(); chan.queueDeclare(name, true, false, true, null); chan.basicConsume(name, true, this); chan.queueBind(name, BusExchange.P2P.toString(), "#"); chan.queueBind(name, BusExchange.BROADCAST.toString(), "#"); } catch (Exception e) { throw new CloudRuntimeException(e); } }
tracker = new MessageTracker(); ConnectionFactory connFactory = new ConnectionFactory(); List<Address> addresses = CollectionUtils.transformToList(serverIps, new Function<Address, String>() { @Override
private static com.rabbitmq.client.ConnectionFactory newRabbitConnectionFactory() { com.rabbitmq.client.ConnectionFactory connectionFactory = new com.rabbitmq.client.ConnectionFactory(); connectionFactory.setAutomaticRecoveryEnabled(false); return connectionFactory; }
ConnectionFactory factory = new ConnectionFactory(); ConnectionDescriptor descriptor = factory.getConnection(myURL); if (descriptor != null) { _httpConnection = (HttpConnection) descriptor.getConnection(); ... }
ConnectionFactory factory = new ConnectionFactory(); factory.setUri("amqp://guest:password@localhost:${amqpPort}"); factory.useSslProtocol() log.info('about to make connection') def connection = factory.newConnection(); //get a channel for sending the "kickoff" message def channel = connection.createChannel();
/** * Create a new SingleConnectionFactory given a {@link URI}. * @param uri the amqp uri configuring the connection */ public SingleConnectionFactory(URI uri) { super(new com.rabbitmq.client.ConnectionFactory()); setUri(uri); }
ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setPreferedTransportTypes(new int[] {..., TransportInfo.TRANSPORT_TCP_CELLULAR,...}); TcpCellularOptions transportOptions = new TcpCellularOptions(); transportOptions.setApn("<your apn>"); transportOptions.setTunnelAuthUsername("<username if required>"); transportOptions.setTunnelAuthPassword("<password if required>"); connectionFactory.setTransportTypeOptions(TransportInfo.TRANSPORT_TCP_CELLULAR, transportOptions);
private com.rabbitmq.client.ConnectionFactory createRabbitConnectionFactory(AmqpServiceInfo serviceInfo) { com.rabbitmq.client.ConnectionFactory connectionFactory = new com.rabbitmq.client.ConnectionFactory(); connectionFactory.setAutomaticRecoveryEnabled(false); if (serviceInfo.getUris() != null && serviceInfo.getUris().size() > 0) { setConnectionFactoryUri(connectionFactory, serviceInfo.getUris().get(0)); } else { setConnectionFactoryUri(connectionFactory, serviceInfo.getUri()); } return connectionFactory; }
private com.rabbitmq.client.ConnectionFactory createRabbitConnectionFactory(AmqpServiceInfo serviceInfo) { com.rabbitmq.client.ConnectionFactory connectionFactory = new com.rabbitmq.client.ConnectionFactory(); connectionFactory.setAutomaticRecoveryEnabled(false); if (serviceInfo.getUris() != null && serviceInfo.getUris().size() > 0) { setConnectionFactoryUri(connectionFactory, serviceInfo.getUris().get(0)); } else { setConnectionFactoryUri(connectionFactory, serviceInfo.getUri()); } return connectionFactory; }
@Bean QueueingConsumer queueingConsumer() throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(messageQueueHostname); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(Constants.ANSWERSHEET_DATA_QUEUE, true, false, false, null); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(Constants.ANSWERSHEET_DATA_QUEUE, true, consumer); return consumer; }
@Bean CachingConnectionFactory connectionFactory() throws Exception { final ConnectionFactory cf = new ConnectionFactory(); cf.setUri("amqp://localhost"); final CachingConnectionFactory result = new CachingConnectionFactory(cf); result.setChannelCacheSize(2); result.setChannelCheckoutTimeout(2000); return result; }