use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-client by iitsoftware.
the class TransactionController method discharge.
private synchronized void discharge(TxnIdIF txnId, boolean fail) throws AMQPException {
AMQPMessage msg = new AMQPMessage();
Discharge discharge = new Discharge();
discharge.setTxnId(txnId);
discharge.setFail(new AMQPBoolean(fail));
msg.setAmqpValue(new AmqpValue(discharge));
DeliveryStateIF deliveryState = producer.send(msg);
if (deliveryState instanceof Rejected) {
Rejected rejected = (Rejected) deliveryState;
com.swiftmq.amqp.v100.generated.transport.definitions.Error error = rejected.getError();
if (error != null)
throw new AMQPException(error.getValueString());
else
throw new AMQPException(("Unknown transactiom error"));
}
}
use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-ce by iitsoftware.
the class Replier method serviceRequests.
public void serviceRequests() {
try {
boolean rollback = false;
int i = 0;
while (i < nMsgs) {
TxnIdIF txnIdIF = txc.createTxnId();
consumer.acquire(1, txnIdIF);
AMQPMessage request = consumer.receive();
if (request != null) {
messageFactory.verify(request);
if (!request.isSettled())
request.accept();
Properties prop = request.getProperties();
if (prop == null)
throw new Exception("Properties not set in request: " + request);
AddressIF replyTo = prop.getReplyTo();
if (replyTo == null)
throw new Exception("replyTo not set in request: " + request);
Producer p = getSession().createProducer(replyTo.getValueString(), qos);
AMQPMessage reply = messageFactory.createReplyMessage(request);
reply.setTxnIdIF(txnIdIF);
Properties prop2 = new Properties();
prop2.setTo(replyTo);
prop2.setCorrelationId(prop.getMessageId());
reply.setProperties(prop2);
p.send(reply);
p.close();
} else
throw new Exception("Msg == null at i=" + i);
if (rollback)
txc.rollback(txnIdIF);
else {
txc.commit(txnIdIF);
i++;
}
rollback = !rollback;
}
} catch (Exception e) {
fail("test failed: " + e);
}
}
Aggregations