use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties in project swiftmq-client by iitsoftware.
the class AMQPRepo method add.
AMQPRepo add(File file, String appname) throws Exception {
String filename = file.getName();
String content = loadFile(file);
AMQPMessage request = new AMQPMessage();
Map propMap = new HashMap();
propMap.put(new AMQPString("app"), new AMQPString(appname));
propMap.put(new AMQPString("file"), new AMQPString(filename));
propMap.put(new AMQPString("operation"), new AMQPString("add"));
request.setApplicationProperties(new ApplicationProperties(propMap));
Properties properties = new Properties();
properties.setReplyTo(replyQueue);
request.setProperties(properties);
request.setAmqpValue(new AmqpValue(new AMQPString(content)));
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(filename + " added to 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.generated.messaging.message_format.Properties in project swiftmq-client by iitsoftware.
the class AMQPRepo method remove.
AMQPRepo remove(File file, String appname) throws Exception {
String filename = file.getName();
AMQPMessage request = new AMQPMessage();
Map propMap = new HashMap();
propMap.put(new AMQPString("app"), new AMQPString(appname));
propMap.put(new AMQPString("file"), new AMQPString(filename));
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(filename + " removed from 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.generated.messaging.message_format.Properties in project swiftmq-client by iitsoftware.
the class AMQPRepo method list.
AMQPRepo list(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("list"));
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("Content of repository " + appname + ":");
System.out.println();
int n = Integer.parseInt(((AMQPString) (body.getValue().get(new AMQPString("nfiles")))).getValue());
for (int i = 0; i < n; i++) System.out.println(((AMQPString) (body.getValue().get(new AMQPString("storetime" + i)))).getValue() + "\t" + ((AMQPString) (body.getValue().get(new AMQPString("file" + i)))).getValue());
System.out.println();
} else {
String result = ((AMQPString) (body.getValue().get(new AMQPString("result")))).getValue();
System.out.println(result);
}
return this;
}
use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties in project swiftmq-client by iitsoftware.
the class Properties method decode.
private void decode() throws Exception {
List l = getValue();
AMQPType t = null;
int idx = 0;
// Factory : MessageIdFactory
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
if (t.getCode() != AMQPTypeDecoder.NULL)
messageId = MessageIdFactory.create(t);
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
userId = (AMQPBinary) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'userId' in 'Properties' type: " + e);
}
// Factory : AddressFactory
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
if (t.getCode() != AMQPTypeDecoder.NULL)
to = AddressFactory.create(t);
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
subject = (AMQPString) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'subject' in 'Properties' type: " + e);
}
// Factory : AddressFactory
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
if (t.getCode() != AMQPTypeDecoder.NULL)
replyTo = AddressFactory.create(t);
// Factory : MessageIdFactory
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
if (t.getCode() != AMQPTypeDecoder.NULL)
correlationId = MessageIdFactory.create(t);
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
contentType = (AMQPSymbol) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'contentType' in 'Properties' type: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
contentEncoding = (AMQPSymbol) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'contentEncoding' in 'Properties' type: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
absoluteExpiryTime = (AMQPTimestamp) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'absoluteExpiryTime' in 'Properties' type: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
creationTime = (AMQPTimestamp) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'creationTime' in 'Properties' type: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
groupId = (AMQPString) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'groupId' in 'Properties' type: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
groupSequence = new SequenceNo(((AMQPUnsignedInt) t).getValue());
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'groupSequence' in 'Properties' type: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
replyToGroupId = (AMQPString) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'replyToGroupId' in 'Properties' type: " + e);
}
}
use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties in project swiftmq-client by iitsoftware.
the class Producer method send.
/**
* Send a message to the target. For transactional sends the method returns after settlement has been finished, otherwise when the message has been sent.
*
* @param msg message
* @param persistent whether the message should send/stored durable
* @param priority message priority (default is 5)
* @param ttl time to live (expiration) in milliseconds, default no expiration
* @return delivery state of the message
* @throws AMQPException on error
*/
public DeliveryStateIF send(AMQPMessage msg, boolean persistent, int priority, long ttl) throws AMQPException {
verifyState();
Header header = msg.getHeader();
if (header == null) {
header = new Header();
msg.setHeader(header);
}
header.setDurable(new AMQPBoolean(persistent));
header.setPriority(new AMQPUnsignedByte(priority));
if (ttl >= 0)
header.setTtl(new Milliseconds(ttl));
Properties props = msg.getProperties();
if (props == null) {
props = new Properties();
msg.setProperties(props);
}
if (props.getMessageId() == null)
props.setMessageId(new MessageIdString(nextMsgId()));
props.setTo(new AddressString(target));
String userName = mySession.myConnection.getUserName();
if (userName != null)
props.setUserId(new AMQPBinary(userName.getBytes()));
Semaphore sem = new Semaphore();
try {
POSendMessage po = new POSendMessage(sem, this, msg, msg.getTxnIdIF(), msg.getDeliveryTag());
mySession.dispatch(po);
sem.waitHere();
if (!po.isSuccess())
throw new AMQPException(po.getException());
return po.getDeliveryState();
} catch (Exception e) {
e.printStackTrace();
throw new AMQPException(e.toString());
}
}
Aggregations