List of usage examples for com.rabbitmq.client Channel exchangeDeclare
Exchange.DeclareOk exchangeDeclare(String exchange, BuiltinExchangeType type) throws IOException;
From source file:sonata.kernel.WimAdaptor.messaging.RabbitMqProducer.java
License:Open Source License
@Override public boolean sendMessage(ServicePlatformMessage message) { boolean out = true; // TODO maps the specific Adaptor message to the proper SP topic try {/* w w w. j a va 2 s . c om*/ Channel channel = connection.createChannel(); String exchangeName = brokerConfig.getProperty("exchange"); channel.exchangeDeclare(exchangeName, "topic"); BasicProperties properties = new BasicProperties().builder().appId(WimAdaptorCore.APP_ID) .contentType(message.getContentType()).replyTo(message.getReplyTo()) .correlationId(message.getSid()).build(); channel.basicPublish(exchangeName, message.getTopic(), properties, message.getBody().getBytes("UTF-8")); // System.out.println( // "[northbound] - sending message: " + message + "\n\r - Properties:" + properties); } catch (Exception e) { e.printStackTrace(); out = false; } return out; }
From source file:translators.ToJsonSchool.java
public static void main(String[] args) throws Exception { final String replyQueueName = "teachersJsonReply"; final String EXCHANGE_NAME_SCHOOL = "cphbusiness.bankJSON"; final String exchangeName = ExchangeName.GLOBAL; RabbitConnection rabbitConnection = new RabbitConnection(); Channel channel = rabbitConnection.makeConnection(); channel.exchangeDeclare(exchangeName, "direct"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, exchangeName, "keyBankJSON"); //get banks from queue. "Get banks" component QueueingConsumer consumer = new QueueingConsumer(channel) { @Override//from w ww. jav a 2 s . co m public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String message = new String(body, "UTF-8"); System.out.println("Received msg: " + message); Message messageFromJson = getFromJson(message); sendMsgToBank(messageFromJson, properties.getCorrelationId(), EXCHANGE_NAME_SCHOOL, replyQueueName); } }; channel.basicConsume(queueName, true, consumer); }
From source file:translators.ToJsonSchool.java
private static void sendMsgToBank(Message msg, String corrId, String exchangeName, String replyQueueName) { Gson gson = new Gson(); RabbitConnection rabbitConnection = new RabbitConnection(); Channel channel = rabbitConnection.makeConnection(); try {/*from w ww. j av a2 s . co m*/ channel.exchangeDeclare(exchangeName, "fanout"); AMQP.BasicProperties props = new AMQP.BasicProperties.Builder().correlationId(corrId) .replyTo(replyQueueName).build(); //!!!!!!!!!!!!!!!!!!HUSK!!!!!!!!!!!! //String message = gson.toJson(new DtoJsonBank(msg.getSsn(), msg.getCreditScore(), msg.getLoanAmount(), msg.getLoanDuration())); String message = gson .toJson(new DtoJsonBank(msg.getSsn(), msg.getCreditScore(), msg.getLoanAmount(), "360")); channel.basicPublish(exchangeName, "", props, message.getBytes()); rabbitConnection.closeChannelAndConnection(); System.out.println(" [x] Sent :" + msg.toString() + ""); } catch (IOException ex) { System.out.println("Error in ToJsonSchool class - sendMsgToBank()"); System.out.println(ex.getStackTrace()); } }
From source file:translators.ToOurJsonBank.java
public static void main(String[] args) throws Exception { RabbitConnection rabbitConnection = new RabbitConnection(); Channel channel = rabbitConnection.makeConnection(); channel.exchangeDeclare(ExchangeName.GLOBAL, "direct"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, ExchangeName.GLOBAL, RoutingKeys.OUR_JSON_BANK); QueueingConsumer consumer = new QueueingConsumer(channel) { @Override/* w w w . j ava2 s. c o m*/ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String message = new String(body, "UTF-8"); System.out.println("Received msg: " + message); Message messageFromJson = getFromJson(message); sendMsgToBank(messageFromJson, properties.getCorrelationId(), ExchangeName.OUTPUT_TRANSLATOR_TO_OUR_JSON_BANK, REPLY_QUEUE_NAME); } }; channel.basicConsume(queueName, true, consumer); }
From source file:translators.ToOurJsonBank.java
private static void sendMsgToBank(Message msg, String corrId, String exchangeName, String replyQueueName) { Gson gson = new Gson(); RabbitConnection rabbitConnection = new RabbitConnection(); Channel channel = rabbitConnection.makeConnection(); try {//w w w .ja va 2 s . c o m channel.exchangeDeclare(exchangeName, "fanout"); AMQP.BasicProperties props = new AMQP.BasicProperties.Builder().correlationId(corrId) .replyTo(replyQueueName).build(); String message = gson .toJson(new DtoJsonBank(msg.getSsn(), msg.getCreditScore(), msg.getLoanAmount(), "360")); channel.basicPublish(exchangeName, "", props, message.getBytes()); rabbitConnection.closeChannelAndConnection(); System.out.println(" [x] Sent :" + msg.toString() + ""); } catch (IOException ex) { System.out.println("Error in ToOurJsonBank class - sendMsgToBank()"); System.out.println(ex.getStackTrace()); } }
From source file:translators.ToOurXmlBank.java
public static void main(String[] args) throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(exchangeName, "direct"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, exchangeName, "ourBankSoapXML"); //get banks from queue. "Get banks" component QueueingConsumer consumer = new QueueingConsumer(channel) { @Override//from w w w . ja va 2s.co m public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String message = new String(body, "UTF-8"); Message messageFromJson = getFromJson(message); connectToWebService(messageFromJson, properties.getCorrelationId(), EXCHANGE_NAME_SCHOOL, replyQueueName); } }; channel.basicConsume(queueName, true, consumer); }
From source file:translators.ToXmlSchool.java
public static void main(String[] args) throws IOException { //final String replyQueueName = "replyFromBanks"; final String replyQueueName = "teachersXmlReply"; final String EXCHANGE_NAME_SCHOOL = "cphbusiness.bankXML"; final String exchangeName = ExchangeName.GLOBAL; RabbitConnection rabbitConnection = new RabbitConnection(); Channel channel = rabbitConnection.makeConnection(); channel.exchangeDeclare(exchangeName, "direct"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, exchangeName, "keyBankXML"); //get banks from queue. "Get banks" component QueueingConsumer consumer = new QueueingConsumer(channel) { @Override/*www . j a va 2 s.com*/ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String message = new String(body, "UTF-8"); Message messageFromJson = getFromJson(message); sendMsgToBank(messageFromJson, properties.getCorrelationId(), EXCHANGE_NAME_SCHOOL, replyQueueName); } }; channel.basicConsume(queueName, true, consumer); }
From source file:translators.ToXmlSchool.java
private static void sendMsgToBank(Message msg, String corrId, String exchangeName, String replyQueueName) { Gson gson = new Gson(); RabbitConnection rabbitConnection = new RabbitConnection(); Channel channel = rabbitConnection.makeConnection(); try {// w w w .j a v a 2 s . c o m channel.exchangeDeclare(exchangeName, "fanout"); AMQP.BasicProperties props = new AMQP.BasicProperties.Builder().correlationId(corrId) .replyTo(replyQueueName).build(); String message = makeXmlString(msg); channel.basicPublish(exchangeName, "", props, message.getBytes()); rabbitConnection.closeChannelAndConnection(); System.out.println(" [x] Sent :" + msg.toString() + ""); } catch (IOException ex) { System.out.println("Error in ToXmlSchool class - sendMsgToBank()"); System.out.println(ex.getStackTrace()); } }
From source file:uk.ac.soton.itinnovation.experimedia.arch.ecc.amqpAPI.impl.faces.AMQPFullInterfaceBase.java
public boolean initialise(String iName, UUID providerID, UUID userID, boolean asProvider) { interfaceReady = false;//w w w .j av a 2s . c om // Safety first if (setInitParams(iName, providerID, userID, asProvider) == false) return false; // Get RabbitMQ channel Channel channelImpl = (Channel) amqpChannel.getChannelImpl(); try { // Declare the appropriate exchanges channelImpl.exchangeDeclare(providerExchangeName, "direct"); channelImpl.exchangeDeclare(userExchangeName, "direct"); // Create queue and subscription createQueue(); createSubscriptionComponent(); // Finished interfaceReady = true; } catch (IOException ioe) { String err = "Could not initialise AMQP interface " + iName + ": " + ioe.getMessage(); amqpIntLogger.error(err, ioe); } return interfaceReady; }
From source file:uk.ac.soton.itinnovation.experimedia.arch.ecc.amqpAPI.impl.faces.AMQPHalfInterfaceBase.java
public boolean initialise(String iName, UUID targetID, boolean asProvider) { interfaceReady = false;//from w ww .ja v a 2 s. com // Safety first if (setInitParams(iName, targetID, asProvider) == false) return false; // Get RabbitMQ channel Channel channelImpl = (Channel) amqpChannel.getChannelImpl(); // Either act only as a provider or user of the interface // (But always use the same exchange name) try { channelImpl.exchangeDeclare(providerExchangeName, "direct"); createQueue(); // If we're a provider, then listen to messages sent if (actingAsProvider) createSubscriptionComponent(); // Finished interfaceReady = true; } catch (IOException ioe) { String err = "Could not initialise AMQP interface " + iName + ": " + ioe.getMessage(); amqpIntLogger.error(err, ioe); } return interfaceReady; }