use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8 method createMessagePublishInfo.
private MessagePublishInfo createMessagePublishInfo(final MessageMetaData_1_0.MessageHeader_1_0 header, final NamedAddressSpace addressSpace) {
final String to = header.getTo();
final String subject = header.getSubject() == null ? "" : header.getSubject();
final String exchangeName;
final String routingKey;
if (to != null && !"".equals(to)) {
DestinationAddress destinationAddress = new DestinationAddress(addressSpace, to);
MessageDestination messageDestination = destinationAddress.getMessageDestination();
if (messageDestination instanceof Queue) {
exchangeName = "";
routingKey = messageDestination.getName();
} else if (messageDestination instanceof Exchange) {
exchangeName = messageDestination.getName();
routingKey = "".equals(destinationAddress.getRoutingKey()) ? subject : destinationAddress.getRoutingKey();
} else {
exchangeName = "";
routingKey = to;
}
} else {
exchangeName = "";
routingKey = subject;
}
return new MessagePublishInfo(convertToShortStringForProperty("to", exchangeName), false, false, convertToShortStringForProperty("to' or 'subject", routingKey));
}
use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.
the class AMQChannel method deadLetter.
private void deadLetter(long deliveryTag) {
final UnacknowledgedMessageMap unackedMap = getUnacknowledgedMessageMap();
final MessageConsumerAssociation association = unackedMap.remove(deliveryTag, true);
if (association == null) {
LOGGER.warn("No message found, unable to DLQ delivery tag: " + deliveryTag);
} else {
final MessageInstance messageInstance = association.getMessageInstance();
final ServerMessage msg = messageInstance.getMessage();
int requeues = 0;
if (messageInstance.makeAcquisitionUnstealable(association.getConsumer())) {
requeues = messageInstance.routeToAlternate(new Action<MessageInstance>() {
@Override
public void performAction(final MessageInstance requeueEntry) {
messageWithSubject(ChannelMessages.DEADLETTERMSG(msg.getMessageNumber(), requeueEntry.getOwningResource().getName()));
}
}, null);
}
if (requeues == 0) {
final TransactionLogResource owningResource = messageInstance.getOwningResource();
if (owningResource instanceof Queue) {
final Queue<?> queue = (Queue<?>) owningResource;
final MessageDestination alternateBindingDestination = queue.getAlternateBindingDestination();
if (alternateBindingDestination == null) {
messageWithSubject(ChannelMessages.DISCARDMSG_NOALTEXCH(msg.getMessageNumber(), queue.getName(), msg.getInitialRoutingAddress()));
} else {
messageWithSubject(ChannelMessages.DISCARDMSG_NOROUTE(msg.getMessageNumber(), alternateBindingDestination.getName()));
}
}
}
}
}
use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.
the class AMQChannel method receiveBasicPublish.
@Override
public void receiveBasicPublish(final AMQShortString exchangeName, final AMQShortString routingKey, final boolean mandatory, final boolean immediate) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("RECV[" + _channelId + "] BasicPublish[" + " exchange: " + exchangeName + " routingKey: " + routingKey + " mandatory: " + mandatory + " immediate: " + immediate + " ]");
}
NamedAddressSpace vHost = _connection.getAddressSpace();
if (blockingTimeoutExceeded()) {
message(ChannelMessages.FLOW_CONTROL_IGNORED());
closeChannel(ErrorCodes.MESSAGE_TOO_LARGE, "Channel flow control was requested, but not enforced by sender");
} else {
MessageDestination destination;
if (isDefaultExchange(exchangeName)) {
destination = vHost.getDefaultDestination();
} else {
destination = vHost.getAttainedMessageDestination(exchangeName.toString());
}
// if the exchange does not exist we raise a channel exception
if (destination == null) {
closeChannel(ErrorCodes.NOT_FOUND, "Unknown exchange name: '" + exchangeName + "'");
} else {
MessagePublishInfo info = new MessagePublishInfo(exchangeName, immediate, mandatory, routingKey);
try {
setPublishFrame(info, destination);
} catch (AccessControlException e) {
_connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
}
}
}
}
use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.
the class MessageConverter_Internal_to_v0_8 method getReplyTo.
private String getReplyTo(final InternalMessage serverMsg, final NamedAddressSpace addressSpace) {
String replyTo = serverMsg.getMessageHeader().getReplyTo();
if (replyTo != null) {
DestinationAddress destinationAddress = new DestinationAddress(addressSpace, replyTo);
MessageDestination messageDestination = destinationAddress.getMessageDestination();
final String replyToBindingUrl;
if (messageDestination instanceof Exchange) {
Exchange<?> exchange = (Exchange<?>) messageDestination;
final String routingKeyOption = "".equals(destinationAddress.getRoutingKey()) ? "" : String.format("?routingkey='%s'", destinationAddress.getRoutingKey());
replyToBindingUrl = String.format("%s://%s//%s", exchange.getType(), exchange.getName(), routingKeyOption);
} else if (messageDestination instanceof Queue) {
replyToBindingUrl = String.format("%s:////%s", ExchangeDefaults.DIRECT_EXCHANGE_CLASS, messageDestination.getName());
} else {
replyToBindingUrl = String.format("%s:////?routingkey='%s'", ExchangeDefaults.DIRECT_EXCHANGE_CLASS, destinationAddress.getRoutingKey());
}
return replyToBindingUrl;
}
return null;
}
use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.
the class Session_1_0 method getReceivingDestination.
public ReceivingDestination getReceivingDestination(final Link_1_0<?, ?> link, final Target target) throws AmqpErrorException {
final ReceivingDestination destination;
if (target != null) {
if (Boolean.TRUE.equals(target.getDynamic())) {
MessageDestination tempDestination = createDynamicDestination(link, target.getDynamicNodeProperties(), target.getCapabilities());
if (tempDestination != null) {
target.setAddress(_primaryDomain + tempDestination.getName());
} else {
throw new AmqpErrorException(AmqpError.INTERNAL_ERROR, "Cannot create dynamic destination");
}
}
String addr = target.getAddress();
if (addr == null || "".equals(addr.trim())) {
destination = new AnonymousRelayDestination(getAddressSpace(), target, _connection.getEventLogger());
} else {
DestinationAddress destinationAddress = new DestinationAddress(getAddressSpace(), addr);
MessageDestination messageDestination = destinationAddress.getMessageDestination();
if (messageDestination != null) {
destination = new NodeReceivingDestination(destinationAddress, target.getDurable(), target.getExpiryPolicy(), target.getCapabilities(), _connection.getEventLogger());
} else {
destination = null;
}
}
} else {
destination = null;
}
if (destination == null) {
throw new AmqpErrorException(AmqpError.NOT_FOUND, String.format("Could not find destination for target '%s'", target));
}
return destination;
}
Aggregations