use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-client by iitsoftware.
the class EndpointImpl method poll.
public void poll() {
try {
AMQPMessage msg = consumer.receiveNoWait(this);
if (msg != null) {
Data data = msg.getData().get(0);
dis.reset();
dis.setBuffer(data.getValue());
Dumpable d = Dumpalizer.construct(dis, factory);
if (d instanceof Reply)
requestRegistry.setReply((Reply) d);
else
dispatch((Request) d);
pollerService.execute(poller);
}
} catch (Exception e) {
e.printStackTrace();
close();
}
}
use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-client by iitsoftware.
the class AMQPRepo method remove.
AMQPRepo remove(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("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("Removed 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-ce by iitsoftware.
the class ReceiveTester method test.
public void test() {
try {
Connection connection = Util.createConnection();
Session session = Util.createSession(connection);
Producer producer = session.createProducer(address, qos);
for (int i = 0; i < nMsgs; i++) {
AMQPMessage msg = messageFactory.create(i);
Map map = new HashMap();
map.put(new AMQPString(PROPNAME), new AMQPInt(i));
msg.setApplicationProperties(new ApplicationProperties(map));
producer.send(msg, persistent, 5, -1);
}
Consumer consumer = session.createConsumer(address, 500, qos, true, null);
for (int i = 0; i < nMsgs; i++) {
AMQPMessage msg = consumer.receive(1000);
if (msg != null) {
messageFactory.verify(msg);
if (!msg.isSettled())
msg.accept();
receiveVerifier.add(msg);
} else
throw new Exception("message is null");
}
connection.close();
DeliveryMemory deliveryMemory = consumer.getDeliveryMemory();
System.out.println("Unsettled: " + deliveryMemory.getNumberUnsettled());
connection = Util.createConnection();
session = Util.createSession(connection);
Consumer consumerRecover = session.createConsumer(address, 500, qos, true, null, deliveryMemory);
consumerRecover.close();
session.close();
connection.close();
connection = Util.createConnection();
session = Util.createSession(connection);
consumer = session.createConsumer(address, 500, qos, true, null);
for (; ; ) {
AMQPMessage msg = consumer.receive(1000);
if (msg != null) {
messageFactory.verify(msg);
if (!msg.isSettled())
msg.accept();
receiveVerifier.add(msg);
} else
break;
}
consumer.close();
session.close();
connection.close();
receiveVerifier.verify();
} catch (Exception e) {
e.printStackTrace();
fail("test failed: " + e);
}
}
use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-ce by iitsoftware.
the class SendTester method test.
public void test() {
try {
Connection connection = Util.createConnection();
Session session = Util.createSession(connection);
Producer producer = session.createProducer(address, qos);
for (int i = 0; i < nMsgs; i++) {
AMQPMessage msg = messageFactory.create(i);
Map map = new HashMap();
map.put(new AMQPString(PROPNAME), new AMQPInt(i));
msg.setApplicationProperties(new ApplicationProperties(map));
producer.send(msg, persistent, 5, -1);
}
connection.close();
DeliveryMemory deliveryMemory = producer.getDeliveryMemory();
System.out.println("Unsettled: " + deliveryMemory.getNumberUnsettled());
connection = Util.createConnection();
session = Util.createSession(connection);
Producer producerRecover = session.createProducer(address, qos, deliveryMemory);
producerRecover.close();
session.close();
connection.close();
connection = Util.createConnection();
session = Util.createSession(connection);
Consumer consumer = session.createConsumer(address, 500, qos, true, null);
for (; ; ) {
AMQPMessage msg = consumer.receive(1000);
if (msg != null) {
messageFactory.verify(msg);
if (!msg.isSettled())
msg.accept();
receiveVerifier.add(msg);
} else
break;
}
consumer.close();
session.close();
connection.close();
receiveVerifier.verify();
} catch (Exception e) {
e.printStackTrace();
fail("test failed: " + e);
}
}
use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-ce by iitsoftware.
the class Sender method send.
public void send() {
try {
int txSize = 0;
TxnIdIF txnIdIF = txc.createTxnId();
boolean rollback = false;
int i = 0;
while (i < nMsgs) {
AMQPMessage msg = messageFactory.create(i);
msg.setTxnIdIF(txnIdIF);
producer.send(msg, persistent, 5, -1);
txSize++;
if (txSize == txSendSize) {
if (rollback)
txc.rollback(txnIdIF);
else {
txc.commit(txnIdIF);
i += txSize;
}
rollback = !rollback;
txnIdIF = txc.createTxnId();
txSize = 0;
}
}
if (txSize > 0) {
if (rollback)
txc.rollback(txnIdIF);
else
txc.commit(txnIdIF);
rollback = !rollback;
txSize = 0;
}
} catch (Exception e) {
fail("test failed: " + e);
}
}
Aggregations