1212 * Created by eduard on 06.10.2017.
1313 */
1414public class API {
15- private Channel _channel ;
15+ private com . rabbitmq . client . Channel _channel ;
1616
1717 private final String _queue ;
1818
@@ -28,12 +28,18 @@ public API(String host, int port, String user, String pass, String virtualHost,
2828
2929 public API (String host , int port , String user , String pass , String virtualHost , String queue , int durable , String exchange ) throws Exception {
3030 ConnectionFactory factory = new ConnectionFactory ();
31- factory .setHost (host );
32- factory .setPort (port );
33- factory .setUsername (user );
34- factory .setPassword (pass );
35- factory .setVirtualHost (virtualHost );
36- //factory.setAutomaticRecoveryEnabled(true);
31+
32+ if (host .toLowerCase ().startsWith ("amqp://" )) {
33+ // we got URI connection string
34+ factory .setUri (host );
35+ } else {
36+ factory .setHost (host );
37+ factory .setPort (port );
38+ factory .setUsername (user );
39+ factory .setPassword (pass );
40+ factory .setVirtualHost (virtualHost );
41+ //factory.setAutomaticRecoveryEnabled(true);
42+ }
3743
3844 _connection = factory .newConnection ();
3945 _channel = _connection .createChannel ();
@@ -68,19 +74,19 @@ public API(String host, int port, String user, String pass, String virtualHost,
6874 _exchange = exchange != null ? exchange : "" ;
6975 }
7076
71- public void sendMessage (byte [] msg , String correlationId , String messageId ) throws Exception {
72- sendMessageToQueue (_queue , msg , correlationId , messageId );
77+ public void sendMessageId (byte [] msg , String correlationId , String messageId ) throws Exception {
78+ sendMessageToQueueId (_queue , msg , correlationId , messageId );
7379 }
7480
7581 public void sendMessage (byte [] msg ) throws Exception {
7682 sendMessageToQueue (_queue , msg );
7783 }
7884
7985 public void sendMessageToQueue (String queue , byte [] msg ) throws Exception {
80- sendMessageToQueue (queue , msg , null , null );
86+ sendMessageToQueueId (queue , msg , null , null );
8187 }
8288
83- public void sendMessageToQueue (String queue , byte [] msg , String correlationId , String messageId ) throws Exception {
89+ public void sendMessageToQueueId (String queue , byte [] msg , String correlationId , String messageId ) throws Exception {
8490 AMQP .BasicProperties props = createProperties (correlationId , messageId );
8591 _channel .basicPublish (_exchange , queue , props , msg );
8692 }
@@ -163,7 +169,7 @@ private AMQP.BasicProperties createProperties(String correlationId, String messa
163169 String contentType = ContentType ;
164170 String contentEncoding = null ;
165171 HashMap <String , Object > headers = null ;
166- Integer deliveryMode = null ;
172+ Integer deliveryMode = Integer . valueOf ( 2 ) ;
167173 Integer priority = null ;
168174 //String correlationId= null;
169175 String replyTo = null ;
@@ -174,6 +180,7 @@ private AMQP.BasicProperties createProperties(String correlationId, String messa
174180 String userId = null ;
175181 String appId = null ;
176182 String clusterId = null ;
183+
177184 AMQP .BasicProperties props = new AMQP .BasicProperties (contentType , contentEncoding , headers , deliveryMode , priority , correlationId , replyTo , expiration , messageId , timestamp , type , userId , appId , clusterId );
178185 return props ;
179186 }
0 commit comments