use of com.swiftmq.amqp.v100.client.Session in project swiftmq-ce by iitsoftware.
the class Suite method suite.
public static Test suite() {
int nPairs = Integer.parseInt(System.getProperty("npairs", "10"));
TestSuite suite = new Suite();
try {
Connection connection = Util.createConnection();
Session session = Util.createSession(connection);
CountDownLatch countDownLatch = new CountDownLatch(nPairs);
for (int i = 0; i < nPairs; i++) {
suite.addTest(new Receiver("receive", QoS.AT_MOST_ONCE, Util.getQueueNamePrefix() + (i + 1), connection, session, countDownLatch));
suite.addTest(new Sender("send", QoS.AT_MOST_ONCE, Util.getQueueNamePrefix() + (i + 1), connection, session));
}
} catch (Exception e) {
e.printStackTrace();
}
return suite;
}
use of com.swiftmq.amqp.v100.client.Session in project activemq by apache.
the class SwiftMQClientTest method testSendReceive.
@Test
public void testSendReceive() throws Exception {
String queue = "testqueue";
int nMsgs = 100;
final String dataFormat = "%01024d";
int qos = QoS.AT_MOST_ONCE;
AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
try {
Connection connection = new Connection(ctx, "127.0.0.1", port, false);
connection.setContainerId("client");
connection.setIdleTimeout(-1);
connection.setMaxFrameSize(1024 * 4);
connection.setExceptionListener(new ExceptionListener() {
public void onException(Exception e) {
e.printStackTrace();
}
});
connection.connect();
{
Session session = connection.createSession(10, 10);
Producer p = session.createProducer(queue, qos);
for (int i = 0; i < nMsgs; i++) {
AMQPMessage msg = new AMQPMessage();
System.out.println("Sending " + i);
msg.setAmqpValue(new AmqpValue(new AMQPString(String.format(dataFormat, i))));
p.send(msg);
}
p.close();
session.close();
}
System.out.println("=======================================================================================");
System.out.println(" receiving ");
System.out.println("=======================================================================================");
{
Session session = connection.createSession(10, 10);
Consumer c = session.createConsumer(queue, 100, qos, true, null);
// Receive messages non-transacted
int i = 0;
while (i < nMsgs) {
AMQPMessage msg = c.receive();
if (msg != null) {
final AMQPType value = msg.getAmqpValue().getValue();
if (value instanceof AMQPString) {
String s = ((AMQPString) value).getValue();
assertEquals(String.format(dataFormat, i), s);
System.out.println("Received: " + i);
}
if (!msg.isSettled())
msg.accept();
i++;
}
}
c.close();
session.close();
}
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class TransactedSender method main.
public static void main(String[] args) throws Exception {
final String serverHost = System.getProperty("HOST", "localhost");
final int serverPort = Integer.getInteger("PORT", 5672);
final String address = System.getProperty("ADDRESS", "transaction-example");
final Client client = Client.create();
final ConnectionOptions options = new ConnectionOptions();
options.user(System.getProperty("USER"));
options.password(System.getProperty("PASSWORD"));
try (Connection connection = client.connect(serverHost, serverPort, options)) {
Session session = connection.openSession();
Sender sender = connection.openSender(address);
session.beginTransaction();
sender.send(Message.create("Transacted Hello"));
session.commitTransaction();
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class ClientLocalTransactionContext method handleTransactionDeclareFailed.
private void handleTransactionDeclareFailed(Transaction<TransactionController> transaction) {
ClientFuture<Session> future = transaction.getAttachments().get(DECLARE_FUTURE_NAME);
LOG.trace("Declare of transaction:{} failed", transaction);
ClientException cause = ClientExceptionSupport.convertToNonFatalException(transaction.getCondition());
future.failed(new ClientTransactionDeclarationException(cause.getMessage(), cause));
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class MessageSendTest method doTestSendMessageWithMapPayloadArrivesWithAMQPValueBody.
private void doTestSendMessageWithMapPayloadArrivesWithAMQPValueBody(boolean useSetter) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.remoteFlow().withLinkCredit(10).queue();
// Open a receiver to ensure sender link has processed
peer.expectAttach().respond();
// the inbound flow frame we sent previously before send.
peer.expectFlow();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Sender test started, peer listening on: {}", remoteURI);
final Map<String, UUID> payload = new HashMap<>();
payload.put("1", UUID.randomUUID());
payload.put("2", UUID.randomUUID());
payload.put("3", UUID.randomUUID());
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort()).openFuture().get();
Session session = connection.openSession().openFuture().get();
SenderOptions options = new SenderOptions().deliveryMode(DeliveryMode.AT_MOST_ONCE);
Sender sender = session.openSender("test-qos", options);
// Gates send on remote flow having been sent and received
session.openReceiver("dummy").openFuture().get();
EncodedAmqpValueMatcher bodyMatcher = new EncodedAmqpValueMatcher(payload);
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.setMessageContentMatcher(bodyMatcher);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withPayload(payloadMatcher).accept();
peer.expectDetach().respond();
peer.expectClose().respond();
final Message<Map<String, UUID>> message;
if (useSetter) {
message = Message.<Map<String, UUID>>create().body(payload);
} else {
message = Message.create(payload);
}
final Tracker tracker = sender.send(message);
assertNotNull(tracker);
assertNotNull(tracker.settlementFuture().isDone());
assertNotNull(tracker.settlementFuture().get().settled());
sender.closeAsync().get(10, TimeUnit.SECONDS);
connection.closeAsync().get(10, TimeUnit.SECONDS);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations