use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-ce by iitsoftware.
the class Requestor method sendRequests.
public void sendRequests() {
try {
AddressIF tempDest = consumer.getRemoteAddress();
for (int i = 0; i < nMsgs; i++) {
TxnIdIF txnIdIF = txc.createTxnId();
AMQPMessage request = messageFactory.create(i);
request.setTxnIdIF(txnIdIF);
Properties prop = new Properties();
prop.setReplyTo(tempDest);
request.setProperties(prop);
producer.send(request, persistent, 5, -1);
txc.commit(txnIdIF);
txnIdIF = txc.createTxnId();
AMQPMessage reply = consumer.receive();
if (reply == null)
throw new Exception("Reply is null");
if (!reply.isSettled())
reply.accept();
txc.commit(txnIdIF);
}
} catch (Exception e) {
fail("test failed: " + e);
}
}
use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-client by iitsoftware.
the class AMQPRepo method add.
AMQPRepo add(File file, String appname) throws Exception {
String filename = file.getName();
String content = loadFile(file);
AMQPMessage request = new AMQPMessage();
Map propMap = new HashMap();
propMap.put(new AMQPString("app"), new AMQPString(appname));
propMap.put(new AMQPString("file"), new AMQPString(filename));
propMap.put(new AMQPString("operation"), new AMQPString("add"));
request.setApplicationProperties(new ApplicationProperties(propMap));
Properties properties = new Properties();
properties.setReplyTo(replyQueue);
request.setProperties(properties);
request.setAmqpValue(new AmqpValue(new AMQPString(content)));
producer.send(request);
AMQPMessage reply = consumer.receive(TIMEOUT);
if (reply == null)
throw new Exception("Timeout occurred while waiting for a reply!");
AMQPMap body = (AMQPMap) reply.getAmqpValue().getValue();
boolean success = ((AMQPBoolean) (body.getValue().get(new AMQPString("success")))).getValue();
if (success)
System.out.println(filename + " added to repository " + appname);
else {
String result = ((AMQPString) (body.getValue().get(new AMQPString("result")))).getValue();
System.out.println(result);
}
return this;
}
use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-client by iitsoftware.
the class AMQPRepo method remove.
AMQPRepo remove(File file, String appname) throws Exception {
String filename = file.getName();
AMQPMessage request = new AMQPMessage();
Map propMap = new HashMap();
propMap.put(new AMQPString("app"), new AMQPString(appname));
propMap.put(new AMQPString("file"), new AMQPString(filename));
propMap.put(new AMQPString("operation"), new AMQPString("remove"));
request.setApplicationProperties(new ApplicationProperties(propMap));
Properties properties = new Properties();
properties.setReplyTo(replyQueue);
request.setProperties(properties);
producer.send(request);
AMQPMessage reply = consumer.receive(TIMEOUT);
if (reply == null)
throw new Exception("Timeout occurred while waiting for a reply!");
AMQPMap body = (AMQPMap) reply.getAmqpValue().getValue();
boolean success = ((AMQPBoolean) (body.getValue().get(new AMQPString("success")))).getValue();
if (success)
System.out.println(filename + " removed from repository " + appname);
else {
String result = ((AMQPString) (body.getValue().get(new AMQPString("result")))).getValue();
System.out.println(result);
}
return this;
}
use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-client by iitsoftware.
the class AMQPRepo method list.
AMQPRepo list(String appname) throws Exception {
AMQPMessage request = new AMQPMessage();
Map propMap = new HashMap();
propMap.put(new AMQPString("app"), new AMQPString(appname));
propMap.put(new AMQPString("operation"), new AMQPString("list"));
request.setApplicationProperties(new ApplicationProperties(propMap));
Properties properties = new Properties();
properties.setReplyTo(replyQueue);
request.setProperties(properties);
producer.send(request);
AMQPMessage reply = consumer.receive(TIMEOUT);
if (reply == null)
throw new Exception("Timeout occurred while waiting for a reply!");
AMQPMap body = (AMQPMap) reply.getAmqpValue().getValue();
boolean success = ((AMQPBoolean) (body.getValue().get(new AMQPString("success")))).getValue();
if (success) {
System.out.println("Content of repository " + appname + ":");
System.out.println();
int n = Integer.parseInt(((AMQPString) (body.getValue().get(new AMQPString("nfiles")))).getValue());
for (int i = 0; i < n; i++) System.out.println(((AMQPString) (body.getValue().get(new AMQPString("storetime" + i)))).getValue() + "\t" + ((AMQPString) (body.getValue().get(new AMQPString("file" + i)))).getValue());
System.out.println();
} else {
String result = ((AMQPString) (body.getValue().get(new AMQPString("result")))).getValue();
System.out.println(result);
}
return this;
}
use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-client by iitsoftware.
the class TransactionController method createTxnId.
/**
* Creates a new transaction id.
*
* @return transaction id
* @throws AMQPException on error
*/
public synchronized TxnIdIF createTxnId() throws AMQPException {
if (producer == null) {
producer = mySession.createProducer(Coordinator.DESCRIPTOR_NAME, QoS.AT_LEAST_ONCE);
producer.setTransactionController(true);
Set capa = producer.getDestinationCapabilities();
if (capa != null) {
if (capa.contains(TxnCapability.LOCAL_TRANSACTIONS.getValue()))
supportLocalTransactions = true;
supportDistributedTransactions = capa.contains(TxnCapability.DISTRIBUTED_TRANSACTIONS.getValue());
supportPromotableTransactions = capa.contains(TxnCapability.PROMOTABLE_TRANSACTIONS.getValue());
supportMultiTxnsPerSsn = capa.contains(TxnCapability.MULTI_TXNS_PER_SSN.getValue());
supportMultiSsnsPerTxn = capa.contains(TxnCapability.MULTI_SSNS_PER_TXN.getValue());
}
}
AMQPMessage msg = new AMQPMessage();
msg.setAmqpValue(new AmqpValue(new Declare()));
Declared declared = (Declared) producer.send(msg);
return declared == null ? null : declared.getTxnId();
}
Aggregations