对于具有多个节点的RabbitMqconnectionString感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解rabbitmq的节点类型有哪些,并且为您提供关于.NetWeb.Confi
对于具有多个节点的 RabbitMq connectionString感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解rabbitmq的节点类型有哪些,并且为您提供关于.Net Web.Config Transformations,替换整个ConnectionString部分、Bi-Directional ConvLSTM U-Net with Densley Connected Convolutions、c# – ConfigurationManager.ConnectionStrings.Add、com.rabbitmq.client.ConnectionFactory的实例源码的宝贵知识。
本文目录一览:- 具有多个节点的 RabbitMq connectionString(rabbitmq的节点类型有哪些)
- .Net Web.Config Transformations,替换整个ConnectionString部分
- Bi-Directional ConvLSTM U-Net with Densley Connected Convolutions
- c# – ConfigurationManager.ConnectionStrings.Add
- com.rabbitmq.client.ConnectionFactory的实例源码
具有多个节点的 RabbitMq connectionString(rabbitmq的节点类型有哪些)
如何解决具有多个节点的 RabbitMq connectionString?
我需要使用连接字符串在集群的 rabbitmq 中连接我的应用。
- amqp://guest:guest@localhost:5672/myvhost
- amqp://guest:guest@localhost:5673/myvhost
- amqp://guest:guest@localhost:5674/myvhost
但是rabbitmq页面中的文档,只显示了一个简单的一个节点的示例。
我也这样试过,没有成功:
- amqp://guest:guest@localhost:5672,localhost:5673,localhost:5674/myvhost
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
.Net Web.Config Transformations,替换整个ConnectionString部分
在此之前我只是使用定位器替换名称.
现在设置已加密,没有名称.
<connectionStrings configProtectionProvider="Pkcs12Provider"> <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#"> <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes192-cbc" /> <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"> <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#"> <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" /> <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"> <KeyName>rsaKey</KeyName> </KeyInfo> <CipherData> <CipherValue>CipherValueHere</CipherValue> </CipherData> </EncryptedKey> </KeyInfo> <CipherData> <CipherValue>CipherValueHere</CipherValue> </CipherData> </EncryptedData>
如何更新我的转换以用此替换整个连接字符串部分?是否有元素名称“connectionStrings”的定位器?
非常感谢,
约翰
解决方法
<connectionStrings xdt:Transform="Replace">
xdt:Transform =“Replace”会做的伎俩.干杯!!
Bi-Directional ConvLSTM U-Net with Densley Connected Convolutions
Bi-Directional ConvLSTM U-Net with Densley Connected Convolutions
ICCV workshop 2019
2019-09-15 11:06:20
Paper: https://arxiv.org/pdf/1909.00166.pdf
Code (Python 3 + Keras - tensorflow backend): https://github.com/rezazad68/BCDU-Net
1. The Proposed Method:
本文提出一种结合 U-Net,BConvLSTM 和 dense convolution 的分割模型,如下图所示:
1.1 Encoding Path
就是用 CNN 提取特征;
1.2 Decoding Path:
在常规的 U-Net 中,他们直接将 encoded feature 直接拷贝并且结合到 decoding 的分支中。
本文提出使用 BConvLSTM 的方法来处理 encoding 和 decoding feature,更好的进行结合。如图 3 所示:
此处使用的 ConvLSTM 是来自于:Convolutional LSTM Network: A Machine Learning Approach for Precipitation Nowcasting,NIPS 2015。该模型包含 input gate, output gate, forget gate, and a memory cell.
作者所用的模型,是来自于 BConvLSTM,双向 ConvLSTM 模型,从前向和后向两个方向编码输入的特征 $X_e, \hat{X_d^{up}}$。
==
c# – ConfigurationManager.ConnectionStrings.Add
但是,如果我使用它,它会抛出“只读”错误消息.我对该问题的研究表明,我们无法在运行时以编程方式将连接字符串添加到app.config中.有一种解决方法,使用反射将ReadOnly标志设置为false
这是反射的例子:
public static void AddConnectionString(sqlConnectionStringBuilder connectionString,string Name) { try { typeof(ConfigurationElementCollection).GetField("bReadOnly",BindingFlags.Instance | BindingFlags.NonPublic).SetValue(ConfigurationManager.ConnectionStrings,false); ConfigurationManager.ConnectionStrings.Add(new ConnectionStringSettings(Name,connectionString.ConnectionString)); EventLogger.LogEvent("Added ConnectionString",1); ProtectConnectionStrings(); } catch (Exception ex) { EventLogger.LogError(ex.Message,(int)EventLogger.Events.GeneralException); } }
但这对我来说都没有意义.我想在app.config中存储conStrs,以便我可以加密它们.我需要用户能够在运行时将它们添加到app.config.完成此任务的标准方法是什么?
解决方法
我想说如果用户正在修改它,它应该存储在设置中.
或者,您可以创建自定义配置文件并使用相同的System.Configuration内容来访问它.但它有点笨拙,我不知道你会通过常规设置文件得到什么.
com.rabbitmq.client.ConnectionFactory的实例源码
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,null); channel.basicpublish("","flink-test",new BasicProperties.Builder() .correlationId(java.util.UUID.randomUUID().toString()).build(),message.getBytes()); } scanner.close(); channel.close(); newConnection.close(); }
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(); }
public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection conn = factory.newConnection(); Channel channel = conn.createChannel(); channel.exchangeDeclare(EXCHANGE_NAME,BuiltinExchangeType.FANOUT); String msg = getMessage(argv); Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy @ HH:mm:ss"); String sDate = sdf.format(date); String finalMsg = sDate + ": " + msg; channel.basicpublish(EXCHANGE_NAME,finalMsg.getBytes("UTF-8")); System.out.println("emmited message: " + finalMsg); channel.close(); conn.close(); }
/** * @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,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(); }
/** * @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,message.getBytes()); System.out.println("RoutingSendDirect Send" + routingKey + "':'" + message); } channel.close(); connection.close(); }
public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); // factory.setHost(""); factory.setUri("amqp://alpha.netkiller.cn"); factory.setUsername("admin"); // factory.setPassword("admin123"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME,null); String message = "Hello World!"; channel.basicpublish("",QUEUE_NAME,message.getBytes()); System.out.println(" [x] Sent '" + message + "'"); channel.close(); connection.close(); }
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.DIRECT); String severity = getSeverity(argv); String message = getMessage(argv); channel.basicpublish(EXCHANGE_NAME,severity,message.getBytes("UTF-8")); System.out.println(" [x] Sent '" + severity + "':'" + message + "'"); channel.close(); connection.close(); }
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,null); String message = getMessage(argv); channel.basicpublish("",message.getBytes("UTF-8")); System.out.println(" [x] Sent '" + message + "'"); channel.close(); connection.close(); }
/** * @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,message.getBytes()); System.out.println("EmitLog Sent '" + message + "'"); } channel.close(); connection.close(); }
private void updateTaskStatus(TaskStatus status) { logger.info("[Study = " + taskStudy + "] [Unit = "+ unitId + "] Sending task update to server. Task id = [" + task.getId() + "] status = ["+status.toString()+"]"); final String QUEUE_NAME = SystemConstants.UBONGO_SERVER_TASKS_STATUS_QUEUE; try { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(serverAddress); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME,null); task.setStatus(status); RabbitData message = new RabbitData(task,MachineConstants.UPDATE_TASK_REQUEST); channel.basicpublish("",message.getBytes()); if (logger.isDebugEnabled()) { logger.debug(" [!] Sent '" + message.getMessage() + "'"); } channel.close(); connection.close(); } catch (Exception e){ logger.error("[Study = " + taskStudy + "] [Unit = "+ unitId + "] Failed sending task status to server. Task id = [" + task.getId() + "] Status = [" + status.toString() + "] error: " + e.getMessage(),e); } }
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,null); System.out.println(" [*] Waiting for messages..."); queueingConsumer consumer = new queueingConsumer(channel); channel.basicConsume(queueName,consumer); while (true) { queueingConsumer.Delivery delivery = consumer.nextDelivery(); String message = new String(delivery.getBody()); System.out.println(" [x] Received '" + message + "'"); } }
/** * 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; }
public static void main(String[] args) throws Exception { //建立连接工厂 ConnectionFactory factory = new ConnectionFactory(); //设置连接地址 factory.setHost("seaof-153-125-234-173.jp-tokyo-10.arukascloud.io"); factory.setPort(31084); //获取连接 Connection connection = factory.newConnection(); //获取渠道 Channel channel = connection.createChannel(); //声明交换机类型 channel.exchangeDeclare(EXCHANGE_NAME,"fanout"); //产生随机数字 String message = RandomStringUtils.randomNumeric(8); channel.basicpublish(EXCHANGE_NAME,message.getBytes()); channel.close(); connection.close(); }
public static void main(String[] args) throws IOException,TimeoutException { //建立连接工厂 ConnectionFactory factory = new ConnectionFactory(); //设置连接地址 factory.setHost("seaof-153-125-234-173.jp-tokyo-10.arukascloud.io"); factory.setPort(31084); //获取连接 Connection connection = factory.newConnection(); //获取渠道 Channel channel = connection.createChannel(); //声明队列,如果不存在就新建 //参数1队列名称;参数2是否持久化;参数3排他性队列,连接断开自动删除;参数4是否自动删除;参数5.参数 channel.queueDeclare(QUEUE_NAME,null); //发送的消息 String message = Thread.currentThread().getName() + "Hello "; //参数1 交换机;参数2 路由键;参数3 基础属性;参数4 消息体 channel.basicpublish("",message.getBytes()); System.out.println(Thread.currentThread().getName() + "[send]" + message); channel.close(); connection.close(); }
/** * 注册主机 * * @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); }
private ConnectionFactory createConnectionFactory() throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setUsername(this.config.getUsername()); factory.setPassword(this.config.getpassword()); factory.setVirtualHost(this.config.getVirtualHost()); factory.setAutomaticRecoveryEnabled(true); factory.setConnectionTimeout(this.config.getConnectionTimeout()); factory.setNetworkRecoveryInterval(this.config.getNetworkRecoveryInterval()); if (this.threadFactory != null) { factory.setThreadFactory(this.threadFactory); } return factory; }
public static ConfigDef config() { return new ConfigDef() .define(HOST_CONfig,ConfigDef.Type.STRING,ConnectionFactory.DEFAULT_HOST,ConfigDef.Importance.HIGH,HOST_DOC) .define(USERNAME_CONfig,ConnectionFactory.DEFAULT_USER,USERNAME_DOC) .define(PASSWORD_CONfig,ConnectionFactory.DEFAULT_PASS,PASSWORD_DOC) .define(VIRTUAL_HOST_CONfig,ConnectionFactory.DEFAULT_VHOST,VIRTUAL_HOST_DOC) .define(REQUESTED_CHANNEL_MAX_CONfig,ConfigDef.Type.INT,ConnectionFactory.DEFAULT_CHANNEL_MAX,ConfigDef.Importance.LOW,REQUESTED_CHANNEL_MAX_DOC) .define(REQUESTED_FRAME_MAX_CONfig,ConnectionFactory.DEFAULT_FRAME_MAX,REQUESTED_FRAME_MAX_DOC) .define(CONNECTION_TIMEOUT_CONfig,ConnectionFactory.DEFAULT_CONNECTION_TIMEOUT,CONNECTION_TIMEOUT_DOC) .define(HANDSHAKE_TIMEOUT_CONfig,ConnectionFactory.DEFAULT_HANDSHAKE_TIMEOUT,HANDSHAKE_TIMEOUT_DOC) .define(SHUTDOWN_TIMEOUT_CONfig,ConnectionFactory.DEFAULT_SHUTDOWN_TIMEOUT,SHUTDOWN_TIMEOUT_DOC) .define(REQUESTED_HEARTBEAT_CONfig,ConnectionFactory.DEFAULT_HEARTBEAT,REQUESTED_HEARTBEAT_DOC) .define(AUTOMATIC_RECOVERY_ENABLED_CONfig,ConfigDef.Type.BOOLEAN,AUTOMATIC_RECOVERY_ENABLED_DOC) .define(TOPOLOGY_RECOVERY_ENABLED_CONfig,TOPOLOGY_RECOVERY_ENABLED_DOC) .define(NETWORK_RECOVERY_INTERVAL_CONfig,10000,NETWORK_RECOVERY_INTERVAL_DOC) .define(PORT_CONfig,ConnectionFactory.DEFAULT_AMQP_PORT,ConfigDef.Importance.MEDIUM,PORT_DOC); }
/** * @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,null); channel.basicQos(1); queueingConsumer consumer = new queueingConsumer(channel); channel.basicConsume(RPC_QUEUE_NAME,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); } }
/** * @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,consumer); }
/** * @param args * @throws TimeoutException * @throws IOException * @date 2017年7月13日 下午2:53:18 * @writer junehappylove */ public static void main(String[] args) throws IOException,"direct"); // 获取匿名队列名称 String queueName = channel.queueDeclare().getQueue(); // 根据路由关键字进行绑定 for (String routingKey : routingKeys1) { channel.queueBind(queueName,routingKey); System.out.println("ReceiveLogsDirect1 exchange:" + EXCHANGE_NAME_ROUTING + "," + " queue:" + queueName + ",BindRoutingKey:" + routingKey); } System.out.println("ReceiveLogsDirect1 Waiting for messages"); Consumer consumer = new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag,byte[] body) throws IOException { String message = new String(body,"UTF-8"); System.out.println("ReceiveLogsDirect1 Received '" + envelope.getRoutingKey() + "':'" + message + "'"); } }; channel.basicConsume(queueName,consumer); }
/** * @param args * @throws TimeoutException * @throws IOException * @date 2017年7月11日 下午5:21:46 * @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 = null; Channel channel = null; try { // 创建一个新的连接 connection = factory.newConnection(); // 创建一个通道 channel = connection.createChannel(); // 声明一个队列 // queueDeclare第一个参数表示队列名称 //第二个参数为是否持久化(true表示是,队列将在服务器重启时生存) //第三个参数为是否是独占队列(创建者可以使用的私有队列,断开后自动删除) //第四个参数为当所有消费者客户端连接断开时是否自动删除队列 //第五个参数为队列的其他参数 channel.queueDeclare(QUEUE_NAME,null); String message = "{\"temperature\":100}"; // 发送消息到队列中 //basicpublish第一个参数为交换机名称 //第二个参数为队列映射的路由key //第三个参数为消息的其他属性 //第四个参数为发送信息的主体 channel.basicpublish("",message.getBytes("UTF-8")); System.out.println("Producer Send +'" + message + "'"); } catch (Exception e) { e.printstacktrace(); } finally { // 关闭通道和连接 channel.close(); connection.close(); } }
/** * @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,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,"UTF-8"); System.out.println("Customer Received '" + message + "'"); } }; // 自动回复队列应答 -- RabbitMQ中的消息确认机制 channel.basicConsume(QUEUE_NAME,consumer); }
/** * @param args * @throws TimeoutException * @throws IOException * @date 2017年7月13日 下午2:40:52 * @writer junehappylove */ public static void main(String[] args) throws IOException,"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,"UTF-8"); System.out.println("ReceiveLogs1 Received '" + message + "'"); } }; channel.basicConsume(queueName,consumer);// 队列会自动删除 }
/** * @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,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(); } } }
/** * @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,byte[] body) throws UnsupportedEncodingException { String message = new String(body,"UTF-8"); System.out.println("ReceiveLogsTopic2 Received '" + envelope.getRoutingKey() + "':'" + message + "'"); } }; channel.basicConsume(queueName,consumer); }
/** * @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,routingKey); System.out.println("ReceiveLogsTopic1 exchange:" + EXCHANGE_NAME_TOPIC + ",BindRoutingKey:" + routingKey); } System.out.println("ReceiveLogsTopic1 Waiting for messages"); Consumer consumer = new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag,"UTF-8"); System.out.println("ReceiveLogsTopic1 Received '" + envelope.getRoutingKey() + "':'" + message + "'"); } }; channel.basicConsume(queueName,consumer); }
@Test public void createConnectionFactory() { int requestedHeartbeat = 121,port = 8889; String host = "testHost",password = "testPassword",username = "testUsername",virtualHost = "testVirtualHost"; RabbitMqConfig rabbitMqConfig = new RabbitMqConfigBuilder() .setRequestedHeartbeat(requestedHeartbeat) .setHost(host) .setPassword(password) .setPort(port) .setUsername(username) .setVirtualHost(virtualHost) .build(); RabbitMqChannelProvider rabbitMqChannelProvider = new RabbitMqChannelProvider(rabbitMqConfig); ConnectionFactory connectionFactory = rabbitMqChannelProvider.createConnectionFactory(); assertEquals(requestedHeartbeat,connectionFactory.getRequestedHeartbeat()); assertEquals(port,connectionFactory.getPort()); assertEquals(host,connectionFactory.getHost()); assertEquals(password,connectionFactory.getpassword()); assertEquals(username,connectionFactory.getUsername()); assertEquals(virtualHost,connectionFactory.getVirtualHost()); }
@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,null); } catch (Exception e) { logger.warn(e.getMessage()); } }
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(); } }
@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,null); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); DefaultConsumer consumer = new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag,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,consumer); }
public static void main(String[] argv) { Connection connection = null; Channel channel = null; try { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); connection = factory.newConnection(); channel = connection.createChannel(); channel.exchangeDeclare(EXCHANGE_NAME,BuiltinExchangeType.TOPIC); String routingKey = getRouting(argv); String message = getMessage(argv); channel.basicpublish(EXCHANGE_NAME,message.getBytes("UTF-8")); System.out.println(" [x] Sent '" + routingKey + "':'" + message + "'"); } catch (Exception e) { e.printstacktrace(); } finally { if (connection != null) { try { connection.close(); } catch (Exception ignore) {} } } }
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,null); String message = "Hello World!"; channel.basicpublish("",message.getBytes("UTF-8")); System.out.println(" [x] Sent '" + message + "'"); channel.close(); connection.close(); }
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; }
protected void connect() throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); channel = connection.createChannel(); String queueName = "flowing-retail-" + name; channel.queueDeclare(queueName,null); channel.exchangeDeclare(EXCHANGE_NAME,"fanout",true); // publish/subscribe model channel.queueBind(queueName,"*"); System.out.println(" [*] Waiting for messages."); Consumer consumer = new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag,byte[] body) throws IOException { String message = new String(body,"UTF-8"); System.out.println(" [x] Received '" + message + "'"); eventHandler.handleEvent(message); } }; channel.basicConsume(queueName,consumer); }
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,null); String message = "Hello World!"; channel.basicpublish("",queueName,message.getBytes()); System.out.println(" [x] Sent '" + message + "'"); channel.close(); connection.close(); }
我们今天的关于具有多个节点的 RabbitMq connectionString和rabbitmq的节点类型有哪些的分享已经告一段落,感谢您的关注,如果您想了解更多关于.Net Web.Config Transformations,替换整个ConnectionString部分、Bi-Directional ConvLSTM U-Net with Densley Connected Convolutions、c# – ConfigurationManager.ConnectionStrings.Add、com.rabbitmq.client.ConnectionFactory的实例源码的相关信息,请在本站查询。
本文标签: