本文整理汇总了Java中com.rabbitmq.client.ConnectionFactory.setPassword方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectionFactory.setPassword方法的具体用法?Java ConnectionFactory.setPassword怎么用?Java ConnectionFactory.setPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rabbitmq.client.ConnectionFactory
的用法示例。
在下文中一共展示了ConnectionFactory.setPassword方法的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: create
import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
static ConnectionProvider create(final RabbitMqConfig config, final DefaultSslConfigurator sslConfigurator) {
final ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setUsername(config.username());
connectionFactory.setPassword(config.password());
connectionFactory.setVirtualHost(config.virtualHost());
connectionFactory.setAutomaticRecoveryEnabled(config.networkRecoveryEnabled());
connectionFactory.setTopologyRecoveryEnabled(config.topologyRecoveryEnabled());
connectionFactory.setConnectionTimeout((int) config.connectionTimeout().toMillis());
connectionFactory.setHandshakeTimeout((int) config.handshakeTimeout().toMillis());
connectionFactory.setShutdownTimeout((int) config.shutdownTimeout().toMillis());
connectionFactory.setNetworkRecoveryInterval(config.networkRecoveryInterval().toMillis());
connectionFactory.setRequestedHeartbeat((int) config.heartbeat().getSeconds());
connectionFactory.setRequestedChannelMax(config.channelLimit());
connectionFactory.setRequestedFrameMax(config.frameSizeLimit());
if (config.nonBlockingIoEnabled()) {
connectionFactory.useNio();
} else {
connectionFactory.useBlockingIo();
}
if (config.sslEnabled()) {
sslConfigurator.configure(connectionFactory, config);
}
return new RabbitConnectionProvider(config, connectionFactory);
}
示例3: 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();
}
}
}
示例4: main
import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
/**
* @param args
* @throws TimeoutException
* @throws IOException
* @throws InterruptedException
* @throws ConsumerCancelledException
* @throws ShutdownSignalException
*/
public static void main(String[] args) throws IOException, TimeoutException, ShutdownSignalException,
ConsumerCancelledException, InterruptedException {
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(RPC_QUEUE_NAME, false, false, false, null);
channel.basicQos(1);
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(RPC_QUEUE_NAME, false, consumer);
System.out.println("RPCServer Awating RPC request");
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
BasicProperties props = delivery.getProperties();
BasicProperties replyProps = new AMQP.BasicProperties.Builder().correlationId(props.getCorrelationId())
.build();
String message = new String(delivery.getBody(), "UTF-8");
int n = Integer.parseInt(message);
System.out.println("RPCServer fib(" + message + ")");
String response = "" + fib(n);
channel.basicPublish("", props.getReplyTo(), replyProps, response.getBytes());
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
}
}
示例5: connection
import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
public static Connection connection() throws IOException, TimeoutException {
if(connection == null) {
synchronized(GabrielData.class) {
if(connection != null) return connection;
Config config = config();
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setHost(config.rabbitMQHost);
connectionFactory.setPort(config.rabbitMQPort);
connectionFactory.setUsername(config.rabbitMQUsername);
connectionFactory.setPassword(config.rabbitMQPassword);
connection = connectionFactory.newConnection();
generalPurposeChannel = connection.createChannel();
GatewayInfo.init(generalPurposeChannel);
}
}
return connection;
}
示例6: main
import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
/**
* @param args
* @throws IOException
* @throws TimeoutException
* @date 2017年7月13日 下午3:06:20
* @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_TOPIC, "topic");
String queueName = channel.queueDeclare().getQueue();
// 路由关键字
String[] routingKeys = new String[] { "*.orange.*" };
// 绑定路由
for (String routingKey : routingKeys) {
channel.queueBind(queueName, EXCHANGE_NAME_TOPIC, routingKey);
System.out.println("ReceiveLogsTopic1 exchange:" + EXCHANGE_NAME_TOPIC + ", queue:" + queueName
+ ", BindRoutingKey:" + routingKey);
}
System.out.println("ReceiveLogsTopic1 Waiting for messages");
Consumer consumer = new DefaultConsumer(channel) {
@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("ReceiveLogsTopic1 Received '" + envelope.getRoutingKey() + "':'" + message + "'");
}
};
channel.basicConsume(queueName, true, consumer);
}
示例7: 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);
}
示例8: main
import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
/**
* @param args
* @throws TimeoutException
* @throws IOException
* @date 2017年7月13日 下午3:08:40
* @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_TOPIC, "topic");
String queueName = channel.queueDeclare().getQueue();
// 路由关键字
String[] routingKeys = new String[]{"*.*.rabbit", "lazy.#"};
// 绑定路由关键字
for (String bindingKey : routingKeys) {
channel.queueBind(queueName, EXCHANGE_NAME_TOPIC, bindingKey);
System.out.println("ReceiveLogsTopic2 exchange:"+EXCHANGE_NAME_TOPIC+", queue:"+queueName+", BindRoutingKey:" + bindingKey);
}
System.out.println("ReceiveLogsTopic2 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("ReceiveLogsTopic2 Received '" + envelope.getRoutingKey() + "':'" + message + "'");
}
};
channel.basicConsume(queueName, true, consumer);
}
示例9: open
import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
@Override
public void open() {
try {
ConnectionFactory factory = new ConnectionFactory();
// factory.setHost( );
factory.setUri(this.uri);
if (this.username != null) {
factory.setUsername(this.username);
factory.setPassword(this.password);
}
this.connection = factory.newConnection();
this.channel = this.connection.createChannel();
channel.queueDeclare(this.queue, false, false, false, null);
} catch (Exception e) {
logger.warn(e.getMessage());
}
}
示例10: 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();
}
}
示例11: main
import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
/**
* @param args
* @throws TimeoutException
* @throws IOException
* @date 2017年7月13日 下午2:40:52
* @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");
// 产生一个随机的队列名称
String queueName = channel.queueDeclare().getQueue();
channel.queueBind(queueName, EXCHANGE_NAME, "");// 对队列进行绑定
System.out.println("ReceiveLogs1 Waiting for messages");
Consumer consumer = new DefaultConsumer(channel) {
@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("ReceiveLogs1 Received '" + message + "'");
}
};
channel.basicConsume(queueName, true, consumer);// 队列会自动删除
}
示例12: setUp
import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
connectionFactory = new ConnectionFactory();
// connectionFactory.setUri("amqp://guest:[email protected]:" +
// RABBITMQ_OUTSIDE_PORT + "/");
connectionFactory.setHost("localhost");
connectionFactory.setPort(6000);
connectionFactory.setUsername("guest");
connectionFactory.setPassword("guest");
connectionFactory.setVirtualHost("/");
Connection conn = null;
Channel channel = null;
try {
conn = connectionFactory.newConnection();
channel = conn.createChannel();
channel.queueDeclare(TEST_QUEUE, false, false, false, null);
channel.exchangeDeclare(TEST_QUEUE, "direct");
channel.queueBind(TEST_QUEUE, TEST_QUEUE, TEST_QUEUE);
} catch (Exception e) {
throw new ContextedRuntimeException(e).addContextValue("queueName", TEST_QUEUE)
.addContextValue("connectionFactory", ToStringBuilder.reflectionToString(connectionFactory));
}
}
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:27,代码来源:RabbitMQHealthCheckTestIntegration.java
示例13: createFromRabbitMqConfig
import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
default Connection createFromRabbitMqConfig(RabbitMqConfig config){
LOGGER.info("Trying to connect to RabbitMq '{}:{}'.", config.host(), config.port());
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(config.host());
factory.setPort(config.port());
if (StringUtils.isNotBlank(config.login())) {
factory.setUsername(config.login());
factory.setPassword(config.password());
LOGGER.debug("Using login : {} [{}]", config.login(), config.password());
}
factory.setVirtualHost(config.virtualHost());
LOGGER.debug("Use virtualhost {}", config.virtualHost());
try {
//ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
return factory.newConnection();
} catch (IOException e) {
throw new RuntimeException("Unable to create a consumeConnection to Rabbit " + config.host() + ":" + config.port(), e);
}
}
示例14: createConnection
import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
private synchronized Connection createConnection() throws KeyManagementException, NoSuchAlgorithmException, IOException, TimeoutException {
final ConnectionFactory factory = new ConnectionFactory();
factory.setUsername(username);
factory.setPassword(password);
factory.setHost(amqpHost);
factory.setPort(port);
if (virtualHost != null && !virtualHost.isEmpty()) {
factory.setVirtualHost(virtualHost);
} else {
factory.setVirtualHost("/");
}
if (useSsl != null && !useSsl.isEmpty() && useSsl.equalsIgnoreCase("true")) {
factory.useSslProtocol(secureProtocol);
}
final Connection connection = factory.newConnection();
connection.addShutdownListener(disconnectHandler);
connection.addBlockedListener(blockedConnectionHandler);
s_connection = connection;
return s_connection;
}
示例15: createConnectionFactory
import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
private static ConnectionFactory createConnectionFactory(String url){
final URI ampqUrl;
try {
ampqUrl = new URI(url);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
final ConnectionFactory factory = new ConnectionFactory();
factory.setUsername(ampqUrl.getUserInfo().split(":")[0]);
factory.setPassword(ampqUrl.getUserInfo().split(":")[1]);
factory.setHost(ampqUrl.getHost());
factory.setPort(ampqUrl.getPort());
if(ampqUrl.getPath().startsWith("/")) {
factory.setVirtualHost(ampqUrl.getPath().substring(1));
}
return factory;
}