use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties in project swiftmq-ce by iitsoftware.
the class ReplierNonTransacted 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> <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";
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)
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("Source : " + source);
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 consumer
Session session = connection.createSession(50, 50);
Consumer c = session.createConsumer(source, 100, toIntQoS(qosS), true, null);
// Receive messages non-transacted
for (int i = 0; i < nMsgs; i++) {
AMQPMessage request = c.receive();
if (request == null)
break;
AmqpValue value = request.getAmqpValue();
System.out.println("Received: " + ((AMQPString) value.getValue()).getValue());
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();
Producer p = session.createProducer(replyTo.getValueString(), toIntQoS(qosS));
AMQPMessage reply = new AMQPMessage();
Properties prop2 = new Properties();
prop2.setTo(replyTo);
prop2.setCorrelationId(prop.getMessageId());
reply.setProperties(prop2);
String s = "RE: " + ((AMQPString) value.getValue()).getValue();
reply.setAmqpValue(new AmqpValue(new AMQPString(s)));
System.out.println("Send: " + s);
p.send(reply);
p.close();
}
// Close everything down
Thread.sleep(2000);
c.close();
session.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties in project swiftmq-client by iitsoftware.
the class EndpointImpl method performRequest.
public synchronized void performRequest(Request request) {
try {
dos.rewind();
Dumpalizer.dump(dos, request);
AMQPMessage msg = new AMQPMessage();
byte[] bytes = new byte[dos.getCount()];
System.arraycopy(dos.getBuffer(), 0, bytes, 0, bytes.length);
msg.addData(new Data(bytes));
Properties prop = new Properties();
if (connection.getUserName() == null)
prop.setUserId(new AMQPBinary("anonymous".getBytes()));
else
prop.setUserId(new AMQPBinary(connection.getUserName().getBytes()));
prop.setReplyTo(replyAddress);
msg.setProperties(prop);
producer.send(msg);
} catch (Exception e) {
close();
}
}
use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties in project swiftmq-ce by iitsoftware.
the class JMSMappingOutboundTransformer method transform.
public void transform(Delivery delivery) throws AMQPException, JMSException {
jmsTypeProp = getValue(PROP_JMS_TYPE, null);
MessageImpl message = delivery.getMessage();
if (message.propertyExists(amqpNative) && message.getBooleanProperty(amqpNative))
throw new JMSException("Message is an AMQP native transformation");
try {
AMQPMessage amqpMessage = new AMQPMessage();
Header header = new Header();
int deliveryMode = message.getJMSDeliveryMode();
header.setDurable(new AMQPBoolean(deliveryMode == DeliveryMode.PERSISTENT));
header.setPriority(new AMQPUnsignedByte(message.getJMSPriority()));
header.setDeliveryCount(new AMQPUnsignedInt(delivery.getMessageIndex().getDeliveryCount() - 1));
long ttl = message.getJMSExpiration();
if (ttl > 0) {
if (message.propertyExists(Util.PROP_EXPIRATION_CURRENT_TIME_ADD))
header.setTtl(new Milliseconds(ttl - message.getLongProperty(Util.PROP_EXPIRATION_CURRENT_TIME_ADD)));
}
Properties properties = new Properties();
String messageId = message.getJMSMessageID();
if (messageId != null)
properties.setMessageId(new MessageIdString(message.getJMSMessageID()));
if (message.propertyExists(Util.PROP_AMQP_TO_ADDRESS))
properties.setTo(new AddressString(message.getStringProperty(Util.PROP_AMQP_TO_ADDRESS)));
else
properties.setTo(new AddressString(message.getJMSDestination().toString()));
Destination replyTo = message.getJMSReplyTo();
if (replyTo != null)
properties.setReplyTo(new AddressString(replyTo.toString()));
String correlationId = message.getJMSCorrelationID();
if (correlationId != null)
properties.setCorrelationId(new MessageIdString(correlationId));
if (ttl > 0)
properties.setAbsoluteExpiryTime(new AMQPTimestamp(ttl));
long timestamp = message.getJMSTimestamp();
if (timestamp > 0)
properties.setCreationTime(new AMQPTimestamp(timestamp));
Map daMap = null;
Map maMap = null;
Map ftMap = null;
Map apMap = null;
String firstAcquirerName = prefixVendor + "FirstAcquirer";
String subject = prefixVendor + "Subject";
String contentType = prefixVendor + "ContentType";
String contentEncoding = prefixVendor + "ContentEncoding";
String replyToGroupId = prefixVendor + "ReplyToGroupID";
for (Enumeration _enum = message.getPropertyNames(); _enum.hasMoreElements(); ) {
String name = (String) _enum.nextElement();
if (name.equals(amqpNative) || name.equals(messageFormat) || name.equals(Util.PROP_EXPIRATION_CURRENT_TIME_ADD) || name.equals(Util.PROP_AMQP_TO_ADDRESS))
continue;
if (name.equals(firstAcquirerName))
header.setFirstAcquirer(new AMQPBoolean(message.getBooleanProperty(firstAcquirerName)));
else if (name.equals(MessageImpl.PROP_USER_ID))
properties.setUserId(new AMQPBinary(message.getStringProperty(MessageImpl.PROP_USER_ID).getBytes()));
else if (name.equals(subject))
properties.setSubject(new AMQPString(message.getStringProperty(subject)));
else if (name.equals(contentType))
properties.setContentType(new AMQPSymbol(message.getStringProperty(contentType)));
else if (name.equals(contentEncoding))
properties.setContentEncoding(new AMQPSymbol(message.getStringProperty(contentEncoding)));
else if (name.equals("JMSXGroupID") && message.getObjectProperty(Util.PROP_GROUP_ID) instanceof String)
properties.setGroupId(new AMQPString(message.getStringProperty(Util.PROP_GROUP_ID)));
else if (name.equals("JMSXGroupSeq") && message.getObjectProperty(Util.PROP_GROUP_SEQ) instanceof Long)
properties.setGroupSequence(new SequenceNo(message.getLongProperty(Util.PROP_GROUP_SEQ)));
else if (name.equals(replyToGroupId))
properties.setReplyToGroupId(new AMQPString(message.getStringProperty(replyToGroupId)));
else if (name.startsWith(prefixDA)) {
if (daMap == null)
daMap = new HashMap();
daMap.put(new AMQPSymbol(nameTranslator.translate(name.substring(prefixDA.length()))), Util.convertJMStoAMQP(message.getObjectProperty(name)));
} else if (name.startsWith(prefixMA)) {
if (maMap == null)
maMap = new HashMap();
maMap.put(new AMQPSymbol(nameTranslator.translate(name.substring(prefixMA.length()))), Util.convertJMStoAMQP(message.getObjectProperty(name)));
} else if (name.startsWith(prefixFT)) {
if (ftMap == null)
ftMap = new HashMap();
ftMap.put(new AMQPSymbol(nameTranslator.translate(name.substring(prefixFT.length()))), Util.convertJMStoAMQP(message.getObjectProperty(name)));
} else {
if (apMap == null)
apMap = new HashMap();
apMap.put(new AMQPString(nameTranslator.translate(name)), Util.convertJMStoAMQP(message.getObjectProperty(name)));
}
}
if (message.getJMSType() != null) {
if (jmsTypeProp != null) {
if (apMap == null)
apMap = new HashMap();
apMap.put(new AMQPString(jmsTypeProp), Util.convertJMStoAMQP(message.getJMSType()));
} else {
if (maMap == null)
maMap = new HashMap();
maMap.put(new AMQPSymbol("x-opt-jms-type"), new AMQPString(message.getJMSType()));
}
}
amqpMessage.setHeader(header);
amqpMessage.setProperties(properties);
if (daMap != null)
amqpMessage.setDeliveryAnnotations(new DeliveryAnnotations(daMap));
if (maMap != null)
amqpMessage.setMessageAnnotations(new MessageAnnotations(maMap));
if (apMap != null)
amqpMessage.setApplicationProperties(new ApplicationProperties(apMap));
if (ftMap != null)
amqpMessage.setFooter(new Footer(ftMap));
bodyFactory.createBody(message, amqpMessage);
delivery.setAmqpMessage(amqpMessage);
dbos.rewind();
amqpMessage.writeContent(dbos);
byte[] payload = new byte[dbos.getCount()];
System.arraycopy(dbos.getBuffer(), 0, payload, 0, dbos.getCount());
delivery.setData(payload);
delivery.setMessageFormat(0);
} catch (IOException e) {
e.printStackTrace();
throw new AMQPException(e.toString());
}
}
use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties in project swiftmq-ce by iitsoftware.
the class Replier method serviceRequests.
public void serviceRequests() {
try {
for (int i = 0; i < nMsgs; i++) {
TxnIdIF txnIdIF = txc.createTxnId();
AMQPMessage request = consumer.receive();
request.setTxnIdIF(txnIdIF);
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);
txc.commit(txnIdIF);
}
} catch (Exception e) {
fail("test failed: " + e);
}
}
use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties 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);
}
}
Aggregations