use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.
the class SessionHandler method doSendOneMessage.
private void doSendOneMessage(SourceMessageProcessor sourceMessageProcessor, SourceLink sourceLink, Delivery delivery, boolean restart) throws EndWithErrorException {
try {
if (remoteIncomingWindow > 0 && outgoingWindow > 0) {
do {
boolean wasFirstPacket = false;
delivery.setMaxFrameSize(amqpHandler.getMaxFrameSize());
TransferFrame frame = new TransferFrame(channel);
frame.setHandle(new Handle(sourceLink.getHandle()));
frame.setSettled(new AMQPBoolean(sourceLink.getSndSettleMode() == SenderSettleMode.SETTLED.getValue()));
if (delivery.getCurrentPacketNumber() == 0) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", doSendOneMessage, amqpMessage=" + delivery.getAmqpMessage());
long totalSize = delivery.getSize();
wasFirstPacket = true;
sourceLink.incDeliveryCountSnd();
long dId = nextDeliveryId();
frame.setDeliveryId(new DeliveryNumber(dId));
frame.setDeliveryTag(createDeliveryTag(delivery));
TxnIdIF currentTx = sourceLink.getCurrentTx();
if (currentTx != null) {
TransactionalState tState = new TransactionalState();
tState.setTxnId(currentTx);
frame.setState(tState);
transactionRegistry.addToTransaction(currentTx, sourceLink, dId, delivery.getMessageIndex(), totalSize);
totalSize = 0;
}
if (!frame.getSettled().getValue()) {
unsettledOutgoingDeliveries.put(dId, sourceLink);
if (totalSize > 0)
sourceLink.addUnsettled(dId, delivery.getMessageIndex(), totalSize);
else
sourceLink.addUnsettled(dId, delivery.getMessageIndex());
} else {
sourceLink.autoack(delivery.getMessageIndex());
}
incMsgsSent(1);
}
delivery.getNextPacket(frame);
// We may increase the outgoing window and send a flow before
if (wasFirstPacket && outgoingWindow - delivery.getPredictedNumberPackets() < 0) {
outgoingWindow += delivery.getPredictedNumberPackets();
sendFlow();
windowChanged = true;
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", doSendOneMessage, remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", sending message, wasFirstPacket=" + wasFirstPacket + ", maxSize=" + delivery.getMaxPayloadLength() + ", packetSize=" + frame.getPayload().length + ", predictedNumberPackets=" + delivery.getPredictedNumberPackets() + ", currentPacket=" + delivery.getCurrentPacketNumber() + ", hasMore=" + delivery.hasMore());
versionedConnection.send(frame);
if (!frame.getSettled().getValue())
outgoingWindow--;
nextOutgoingId++;
remoteIncomingWindow--;
if (!delivery.hasMore()) {
if (restart) {
if (sourceLink.getLinkCredit() > 0)
sourceLink.startMessageProcessor(sourceMessageProcessor);
else
sourceLink.clearMessageProcessor();
}
// If that was the last packet and outgoing window was increased for this message, we need to reset it and send another flow
if (windowChanged) {
outgoingWindow = initialOutgoingWindow;
sendFlow();
}
break;
}
} while (remoteIncomingWindow > 0 && outgoingWindow > 0);
if (delivery.hasMore()) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", doSendOneMessage, remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", has more but no window, storing message");
outboundDeliveries.add(new OutboundDelivery(sourceMessageProcessor, sourceLink, delivery, restart));
}
} else {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", doSendOneMessage, no remote incoming window = " + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", store for later transfer");
outboundDeliveries.add(new OutboundDelivery(sourceMessageProcessor, sourceLink, delivery, restart));
}
} catch (IOException e) {
throw new ConnectionEndException(AmqpError.INTERNAL_ERROR, new AMQPString("IOException during outbound send: " + e.getMessage()));
} catch (QueueException e) {
throw new ConnectionEndException(AmqpError.INTERNAL_ERROR, new AMQPString("QueueException during outbound send: " + e.getMessage()));
}
}
use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.
the class ReceiverTransactedRetirement method main.
public static void main(String[] args) {
if (args.length == 1 && args[0].equals("?")) {
System.out.println();
System.out.println("Usage: <host> <port> <source> <nmsgs> <qos> <txsize> <authanon> [<username> <password>]");
System.out.println(" <qos> ::= AT_LEAST_ONCE | AT_MOST_ONCE | EXACTLY_ONCE");
System.out.println(" Suppress <username> <password> and set <authanon> to false to avoid SASL.");
System.out.println();
System.exit(0);
}
String host = "localhost";
int port = 5672;
String source = "testqueue";
int nMsgs = 100;
String qosS = "EXACTLY_ONCE";
int txSize = 10;
boolean authAnon = true;
String user = null;
String password = null;
if (args.length >= 1)
host = args[0];
if (args.length >= 2)
port = Integer.parseInt(args[1]);
if (args.length >= 3)
source = args[2];
if (args.length >= 4)
nMsgs = Integer.parseInt(args[3]);
if (args.length >= 5)
qosS = args[4];
if (args.length >= 6)
txSize = Integer.parseInt(args[5]);
if (args.length >= 7)
authAnon = Boolean.parseBoolean(args[6]);
if (args.length >= 8)
user = args[7];
if (args.length >= 9)
password = args[8];
System.out.println();
System.out.println("Host : " + host);
System.out.println("Port : " + port);
System.out.println("Source : " + source);
System.out.println("Number Msgs : " + nMsgs);
System.out.println("QoS : " + qosS);
System.out.println("Tx Size : " + txSize);
System.out.println("Auth as Anon: " + authAnon);
System.out.println("User : " + user);
System.out.println("Password : " + password);
System.out.println();
try {
// Create connection and connect
AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
Connection connection = null;
if (args.length < 8)
connection = new Connection(ctx, host, port, authAnon);
else
connection = new Connection(ctx, host, port, user, password);
if (port == 5671) {
System.out.println("Using SSL on port 5671");
connection.setSocketFactory(new JSSESocketFactory());
}
connection.connect();
// Create session and consumer
Session session = connection.createSession(50, 50);
Consumer c = session.createConsumer(source, 100, toIntQoS(qosS), true, null);
// Get the transaction controller
TransactionController txc = session.getTransactionController();
// Receive messages in transactions in size <txSize>
int currentTxSize = 0;
TxnIdIF txnId = txc.createTxnId();
for (int i = 0; i < nMsgs; i++) {
AMQPMessage msg = c.receive();
if (msg == null)
break;
AmqpValue value = msg.getAmqpValue();
System.out.println("Received: " + ((AMQPString) value.getValue()).getValue());
msg.setTxnIdIF(txnId);
msg.accept();
currentTxSize++;
if ((i + 1) % txSize == 0) {
txc.commit(txnId);
txnId = txc.createTxnId();
currentTxSize = 0;
}
}
if (currentTxSize > 0)
txc.commit(txnId);
// Close everything down
Thread.sleep(2000);
c.close();
session.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.
the class RequestorNonTransacted method main.
public static void main(String[] args) {
if (args.length == 1 && args[0].equals("?")) {
System.out.println();
System.out.println("Usage: <host> <port> <target> <nreq> <qos> <authanon> [<username> <password>]");
System.out.println(" <qos> ::= AT_LEAST_ONCE | AT_MOST_ONCE | EXACTLY_ONCE");
System.out.println(" Suppress <username> <password> and set <authanon> to false to avoid SASL.");
System.out.println();
System.exit(0);
}
String host = "localhost";
int port = 5672;
String target = "testqueue";
int nMsgs = 100;
String qosS = "EXACTLY_ONCE";
boolean authAnon = true;
String user = null;
String password = null;
if (args.length >= 1)
host = args[0];
if (args.length >= 2)
port = Integer.parseInt(args[1]);
if (args.length >= 3)
target = args[2];
if (args.length >= 4)
nMsgs = Integer.parseInt(args[3]);
if (args.length >= 5)
qosS = args[4];
if (args.length >= 6)
authAnon = Boolean.parseBoolean(args[5]);
if (args.length >= 7)
user = args[6];
if (args.length >= 8)
password = args[7];
System.out.println();
System.out.println("Host : " + host);
System.out.println("Port : " + port);
System.out.println("Target : " + target);
System.out.println("Number Req : " + nMsgs);
System.out.println("QoS : " + qosS);
System.out.println("Auth as Anon: " + authAnon);
System.out.println("User : " + user);
System.out.println("Password : " + password);
System.out.println();
try {
// Create connection and connect
AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
Connection connection = null;
if (args.length < 7)
connection = new Connection(ctx, host, port, authAnon);
else
connection = new Connection(ctx, host, port, user, password);
if (port == 5671) {
System.out.println("Using SSL on port 5671");
connection.setSocketFactory(new JSSESocketFactory());
}
connection.connect();
// Create session and producer
Session session = connection.createSession(50, 50);
Producer p = session.createProducer(target, toIntQoS(qosS));
// Create a temp queue and a consumer
Consumer c = session.createConsumer(100, toIntQoS(qosS));
AddressIF tempDest = c.getRemoteAddress();
// Do request / reply
for (int i = 0; i < nMsgs; i++) {
// Send the request
AMQPMessage request = new AMQPMessage();
Properties prop = new Properties();
prop.setReplyTo(tempDest);
request.setProperties(prop);
String s = "Message #" + (i + 1);
System.out.println("Sending " + s);
request.setAmqpValue(new AmqpValue(new AMQPString(s)));
p.send(request);
// Receive the reply
AMQPMessage reply = c.receive();
if (reply == null)
break;
if (!reply.isSettled())
reply.accept();
AmqpValue value = reply.getAmqpValue();
System.out.println("Received: " + ((AMQPString) value.getValue()).getValue());
}
Thread.sleep(2000);
// Close everything down
c.close();
p.close();
session.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.
the class SenderNonTransacted method main.
public static void main(String[] args) {
if (args.length == 1 && args[0].equals("?")) {
System.out.println();
System.out.println("Usage: <host> <port> <target> <nmsgs> <qos> <authanon> [<username> <password>]");
System.out.println(" <qos> ::= AT_LEAST_ONCE | AT_MOST_ONCE | EXACTLY_ONCE");
System.out.println(" Suppress <username> <password> and set <authanon> to false to avoid SASL.");
System.out.println();
System.exit(0);
}
String host = "localhost";
int port = 5672;
String target = "testqueue";
int nMsgs = 100;
String qosS = "EXACTLY_ONCE";
boolean authAnon = true;
String user = null;
String password = null;
if (args.length >= 1)
host = args[0];
if (args.length >= 2)
port = Integer.parseInt(args[1]);
if (args.length >= 3)
target = args[2];
if (args.length >= 4)
nMsgs = Integer.parseInt(args[3]);
if (args.length >= 5)
qosS = args[4];
if (args.length >= 6)
authAnon = Boolean.parseBoolean(args[5]);
if (args.length >= 7)
user = args[6];
if (args.length >= 8)
password = args[7];
System.out.println();
System.out.println("Host : " + host);
System.out.println("Port : " + port);
System.out.println("Target : " + target);
System.out.println("Number Msgs : " + nMsgs);
System.out.println("QoS : " + qosS);
System.out.println("Auth as Anon: " + authAnon);
System.out.println("User : " + user);
System.out.println("Password : " + password);
System.out.println();
try {
// Create connection and connect
AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
Connection connection = null;
if (args.length < 7)
connection = new Connection(ctx, host, port, authAnon);
else
connection = new Connection(ctx, host, port, user, password);
if (port == 5671) {
System.out.println("Using SSL on port 5671");
connection.setSocketFactory(new JSSESocketFactory());
}
connection.connect();
// Create session and producer
Session session = connection.createSession(50, 50);
Producer p = session.createProducer(target, toIntQoS(qosS));
// Send messages non-transacted
for (int i = 0; i < nMsgs; i++) {
AMQPMessage msg = new AMQPMessage();
String s = "Message #" + (i + 1);
System.out.println("Sending " + s);
msg.setAmqpValue(new AmqpValue(new AMQPString(s)));
p.send(msg);
}
Thread.sleep(2000);
// Close everything down
p.close();
session.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.
the class TransactionRegistry method addToTransaction.
public void addToTransaction(TxnIdIF btxnId, SourceLink sourceLink, long deliveryId, MessageIndex messageIndex, long size) throws EndWithErrorException {
String txnId = new String(((TransactionId) btxnId).getValue());
String linkName = sourceLink.getName();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addToTransaction, txnId=" + txnId + ", linkName=" + linkName + ", messageIndex=" + messageIndex);
lock.lock();
try {
ActiveTxEntry activeTxEntry = (ActiveTxEntry) activeTx.get(txnId);
if (activeTxEntry == null) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addToTransaction, txnId=" + txnId + ", not found!");
throw new SessionEndException(TransactionError.UNKNOWN_ID, new AMQPString("Transaction id not found: " + txnId));
}
sourceLink.increaseActiveTransactions();
if (activeTxEntry.outboundTxEntryMap == null)
activeTxEntry.outboundTxEntryMap = new HashMap();
OutboundTxEntry outboundTxEntry = (OutboundTxEntry) activeTxEntry.outboundTxEntryMap.get(deliveryId);
if (outboundTxEntry == null) {
outboundTxEntry = new OutboundTxEntry(sourceLink, messageIndex, null);
activeTxEntry.outboundTxEntryMap.put(deliveryId, outboundTxEntry);
} else {
outboundTxEntry.sourceLink = sourceLink;
outboundTxEntry.messageIndex = messageIndex;
}
} finally {
lock.unlock();
}
}
Aggregations