use of com.swiftmq.jms.smqp.v630.ProduceMessageRequest in project swiftmq-client by iitsoftware.
the class MessageProducerImpl method validate.
public void validate(Request request) throws ValidationException {
if (request instanceof ProduceMessageRequest) {
try {
ProduceMessageRequest r = (ProduceMessageRequest) request;
r.setDispatchId(mySession.dispatchId);
r.setQueueProducerId(producerId);
MessageImpl msg = SMQPUtil.getMessage(r);
Destination dest = msg.getJMSDestination();
// failover
if (dest instanceof TemporaryQueue || dest instanceof TemporaryTopic) {
r.setCancelledByValidator(true);
return;
}
if (isTopicDestination() && clientId != null)
msg.setStringProperty(MessageImpl.PROP_CLIENT_ID, clientId);
msg.setBooleanProperty(MessageImpl.PROP_DOUBT_DUPLICATE, true);
if (r.getSingleMessage() != null)
r.setSingleMessage(msg);
else
r.setMessageCopy(SMQPUtil.toBytes(msg));
} catch (Exception e) {
e.printStackTrace();
throw new ValidationException(e.toString());
}
} else {
CloseProducerRequest r = (CloseProducerRequest) request;
r.setDispatchId(mySession.dispatchId);
r.setQueueProducerId(producerId);
}
}
use of com.swiftmq.jms.smqp.v630.ProduceMessageRequest in project swiftmq-client by iitsoftware.
the class MessageProducerImpl method processSend.
void processSend(int producerId, Message message) throws JMSException {
boolean transacted = mySession.getTransacted();
MessageImpl msg = (MessageImpl) message;
if (transacted) {
mySession.storeTransactedMessage(producerId, msg);
} else {
nSend++;
ProduceMessageReply reply = null;
boolean replyRequired = nSend == replyThreshold || msg.getJMSDeliveryMode() == DeliveryMode.PERSISTENT && !ASYNC_SEND;
try {
reply = (ProduceMessageReply) requestRegistry.request(new ProduceMessageRequest(dispatchId, producerId, msg, replyRequired, !replyRequired));
} catch (Exception e) {
throw ExceptionConverter.convert(e);
}
if (replyRequired) {
if (reply == null)
throw new JMSException("Request was cancelled (reply == null)");
nSend = 0;
if (!reply.isOk()) {
throw ExceptionConverter.convert(reply.getException());
}
currentDelay = reply.getDelay();
if (currentDelay > 0) {
try {
Thread.sleep(currentDelay);
} catch (Exception ignored) {
}
}
}
}
// fix 1.2
msg.reset();
}
use of com.swiftmq.jms.smqp.v630.ProduceMessageRequest in project swiftmq-client by iitsoftware.
the class MessageProducerImpl method processSend.
void processSend(int producerId, Message message) throws JMSException {
boolean transacted = mySession.getTransacted();
MessageImpl msg = (MessageImpl) message;
if (transacted) {
mySession.storeTransactedMessage(producerId, msg);
} else {
nSend++;
ProduceMessageReply reply = null;
boolean replyRequired = nSend == replyThreshold || msg.getJMSDeliveryMode() == DeliveryMode.PERSISTENT && !ASYNC_SEND;
try {
reply = (ProduceMessageReply) requestRegistry.request(new ProduceMessageRequest(dispatchId, producerId, msg, replyRequired, !replyRequired));
} catch (Exception e) {
throw ExceptionConverter.convert(e);
}
if (replyRequired) {
if (reply == null)
throw new JMSException("Request was cancelled (reply == null)");
nSend = 0;
if (!reply.isOk()) {
throw ExceptionConverter.convert(reply.getException());
}
currentDelay = reply.getDelay();
if (currentDelay > 0) {
try {
Thread.sleep(currentDelay);
} catch (Exception ignored) {
}
}
}
}
// fix 1.2
msg.reset();
}
use of com.swiftmq.jms.smqp.v630.ProduceMessageRequest in project swiftmq-client by iitsoftware.
the class MessageProducerImpl method processSend.
void processSend(int producerId, Message message) throws JMSException {
boolean transacted = mySession.getTransacted();
MessageImpl msg = (MessageImpl) message;
if (transacted) {
mySession.storeTransactedMessage(producerId, msg);
} else {
nSend++;
ProduceMessageReply reply = null;
boolean replyRequired = nSend == replyThreshold || msg.getJMSDeliveryMode() == DeliveryMode.PERSISTENT && !ASYNC_SEND;
try {
ProduceMessageRequest request = null;
if (!replyRequired) {
dbos.rewind();
msg.writeContent(dbos);
byte[] b = new byte[dbos.getCount()];
System.arraycopy(dbos.getBuffer(), 0, b, 0, b.length);
request = new ProduceMessageRequest(dispatchId, producerId, null, b);
} else
request = new ProduceMessageRequest(dispatchId, producerId, msg, null);
request.setReplyRequired(replyRequired);
reply = (ProduceMessageReply) requestRegistry.request(request);
} catch (Exception e) {
throw ExceptionConverter.convert(e);
}
if (replyRequired) {
if (reply == null)
throw new JMSException("Request was cancelled (reply == null)");
nSend = 0;
if (!reply.isOk()) {
throw ExceptionConverter.convert(reply.getException());
}
currentDelay = reply.getDelay();
if (currentDelay > 0) {
try {
Thread.sleep(currentDelay);
} catch (Exception ignored) {
}
}
}
}
// fix 1.2
msg.reset();
}
use of com.swiftmq.jms.smqp.v630.ProduceMessageRequest in project swiftmq-client by iitsoftware.
the class MessageProducerImpl method validate.
public void validate(Request request) throws ValidationException {
if (request instanceof ProduceMessageRequest) {
try {
ProduceMessageRequest r = (ProduceMessageRequest) request;
r.setDispatchId(mySession.dispatchId);
r.setQueueProducerId(producerId);
MessageImpl msg = SMQPUtil.getMessage(r);
Destination dest = msg.getJMSDestination();
// failover
if (dest instanceof TemporaryQueue || dest instanceof TemporaryTopic) {
r.setCancelledByValidator(true);
return;
}
msg.setBooleanProperty(MessageImpl.PROP_DOUBT_DUPLICATE, true);
if (r.getSingleMessage() != null)
r.setSingleMessage(msg);
else
r.setMessageCopy(SMQPUtil.toBytes(msg));
} catch (Exception e) {
e.printStackTrace();
throw new ValidationException(e.toString());
}
} else {
CloseProducerRequest r = (CloseProducerRequest) request;
r.setDispatchId(mySession.dispatchId);
r.setQueueProducerId(producerId);
}
}
Aggregations