use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class OpenWireConnection method addDestination.
public void addDestination(DestinationInfo info) throws Exception {
boolean created = false;
ActiveMQDestination dest = info.getDestination();
if (!protocolManager.isSupportAdvisory() && AdvisorySupport.isAdvisoryTopic(dest)) {
return;
}
SimpleString qName = SimpleString.toSimpleString(dest.getPhysicalName());
if (server.locateQueue(qName) == null) {
AddressSettings addressSettings = server.getAddressSettingsRepository().getMatch(dest.getPhysicalName());
AddressInfo addressInfo = new AddressInfo(qName, dest.isTopic() ? RoutingType.MULTICAST : RoutingType.ANYCAST);
if (AdvisorySupport.isAdvisoryTopic(dest) && protocolManager.isSuppressInternalManagementObjects()) {
addressInfo.setInternal(true);
}
if (dest.isQueue() && (addressSettings.isAutoCreateQueues() || dest.isTemporary())) {
try {
internalSession.createQueue(addressInfo, qName, null, dest.isTemporary(), !dest.isTemporary(), !dest.isTemporary());
created = true;
} catch (ActiveMQQueueExistsException exists) {
// The queue may have been created by another thread in the mean time. Catch and do nothing.
}
} else if (dest.isTopic() && (addressSettings.isAutoCreateAddresses() || dest.isTemporary())) {
try {
internalSession.createAddress(addressInfo, !dest.isTemporary());
created = true;
} catch (ActiveMQAddressExistsException exists) {
// The address may have been created by another thread in the mean time. Catch and do nothing.
}
}
}
if (dest.isTemporary()) {
// Openwire needs to store the DestinationInfo in order to send
// Advisory messages to clients
this.state.addTempDestination(info);
}
if (created && !AdvisorySupport.isAdvisoryTopic(dest)) {
AMQConnectionContext context = getContext();
DestinationInfo advInfo = new DestinationInfo(context.getConnectionId(), DestinationInfo.ADD_OPERATION_TYPE, dest);
ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(dest);
protocolManager.fireAdvisory(context, topic, advInfo);
}
}
use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class AMQSession method send.
public void send(final ProducerInfo producerInfo, final Message messageSend, final boolean sendProducerAck) throws Exception {
messageSend.setBrokerInTime(System.currentTimeMillis());
final ActiveMQDestination destination = messageSend.getDestination();
final ActiveMQDestination[] actualDestinations;
final int actualDestinationsCount;
if (destination.isComposite()) {
actualDestinations = destination.getCompositeDestinations();
messageSend.setOriginalDestination(destination);
actualDestinationsCount = actualDestinations.length;
} else {
actualDestinations = null;
actualDestinationsCount = 1;
}
final org.apache.activemq.artemis.api.core.Message originalCoreMsg = OpenWireMessageConverter.inbound(messageSend, protocolManagerWireFormat, coreMessageObjectPools);
assert clientId.toString().equals(this.connection.getState().getInfo().getClientId()) : "Session cached clientId must be the same of the connection";
originalCoreMsg.putStringProperty(MessageUtil.CONNECTION_ID_PROPERTY_NAME, clientId);
/* ActiveMQ failover transport will attempt to reconnect after connection failure. Any sent messages that did
* not receive acks will be resent. (ActiveMQ broker handles this by returning a last sequence id received to
* the client). To handle this in Artemis we use a duplicate ID cache. To do this we check to see if the
* message comes from failover connection. If so we add a DUPLICATE_ID to handle duplicates after a resend. */
if (connection.getContext().isFaultTolerant() && !messageSend.getProperties().containsKey(org.apache.activemq.artemis.api.core.Message.HDR_DUPLICATE_DETECTION_ID.toString())) {
originalCoreMsg.putStringProperty(org.apache.activemq.artemis.api.core.Message.HDR_DUPLICATE_DETECTION_ID, SimpleString.toSimpleString(messageSend.getMessageId().toString()));
}
final boolean shouldBlockProducer = producerInfo.getWindowSize() > 0 || messageSend.isResponseRequired();
final AtomicInteger count = actualDestinations != null ? new AtomicInteger(actualDestinationsCount) : null;
if (shouldBlockProducer) {
connection.getContext().setDontSendReponse(true);
}
for (int i = 0; i < actualDestinationsCount; i++) {
final ActiveMQDestination dest = actualDestinations != null ? actualDestinations[i] : destination;
final String physicalName = dest.getPhysicalName();
final SimpleString address = SimpleString.toSimpleString(physicalName, coreMessageObjectPools.getAddressStringSimpleStringPool());
// the last coreMsg could be directly the original one -> it avoid 1 copy if actualDestinations > 1 and ANY copy if actualDestinations == 1
final org.apache.activemq.artemis.api.core.Message coreMsg = (i == actualDestinationsCount - 1) ? originalCoreMsg : originalCoreMsg.copy();
coreMsg.setAddress(address);
if (dest.isQueue()) {
checkCachedExistingQueues(address, physicalName, dest.isTemporary());
coreMsg.setRoutingType(RoutingType.ANYCAST);
} else {
coreMsg.setRoutingType(RoutingType.MULTICAST);
}
final PagingStore store = server.getPagingManager().getPageStore(address);
this.connection.disableTtl();
if (shouldBlockProducer) {
sendShouldBlockProducer(producerInfo, messageSend, sendProducerAck, store, dest, count, coreMsg, address);
} else {
// non-persistent messages goes here, by default we stop reading from
// transport
connection.getTransportConnection().setAutoRead(false);
if (!store.checkMemory(enableAutoReadAndTtl)) {
enableAutoReadAndTtl();
throw new ResourceAllocationException("Queue is full " + address);
}
getCoreSession().send(coreMsg, false, dest.isTemporary());
if (count == null || count.decrementAndGet() == 0) {
if (sendProducerAck) {
final ProducerAck ack = new ProducerAck(producerInfo.getProducerId(), messageSend.getSize());
connection.dispatchAsync(ack);
}
}
}
}
}
use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class OpenWireMessageConverter method setAMQMsgOriginalDestination.
private static void setAMQMsgOriginalDestination(final ActiveMQMessage amqMsg, final WireFormat marshaller, final byte[] origDestBytes) throws IOException {
ActiveMQDestination origDest = (ActiveMQDestination) marshaller.unmarshal(new ByteSequence(origDestBytes));
amqMsg.setOriginalDestination(origDest);
}
use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class OpenWireMessageConverter method setAMQMsgReplyTo.
private static void setAMQMsgReplyTo(final ActiveMQMessage amqMsg, final WireFormat marshaller, final byte[] replyToBytes) throws IOException {
ActiveMQDestination replyTo = (ActiveMQDestination) marshaller.unmarshal(new ByteSequence(replyToBytes));
amqMsg.setReplyTo(replyTo);
}
use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class OpenWireMessageConverter method inbound.
public static org.apache.activemq.artemis.api.core.Message inbound(final Message messageSend, final WireFormat marshaller, final CoreMessageObjectPools coreMessageObjectPools) throws Exception {
final CoreMessage coreMessage = new CoreMessage(-1, messageSend.getSize(), coreMessageObjectPools);
final String type = messageSend.getType();
if (type != null) {
coreMessage.putStringProperty(JMS_TYPE_PROPERTY, new SimpleString(type));
}
coreMessage.setDurable(messageSend.isPersistent());
coreMessage.setExpiration(messageSend.getExpiration());
coreMessage.setPriority(messageSend.getPriority());
coreMessage.setTimestamp(messageSend.getTimestamp());
final byte coreType = toCoreType(messageSend.getDataStructureType());
coreMessage.setType(coreType);
final ActiveMQBuffer body = coreMessage.getBodyBuffer();
final ByteSequence contents = messageSend.getContent();
if (contents == null && coreType == org.apache.activemq.artemis.api.core.Message.TEXT_TYPE) {
body.writeNullableString(null);
} else if (contents != null) {
final boolean messageCompressed = messageSend.isCompressed();
if (messageCompressed) {
coreMessage.putBooleanProperty(AMQ_MSG_COMPRESSED, messageCompressed);
}
switch(coreType) {
case org.apache.activemq.artemis.api.core.Message.TEXT_TYPE:
writeTextType(contents, messageCompressed, body);
break;
case org.apache.activemq.artemis.api.core.Message.MAP_TYPE:
writeMapType(contents, messageCompressed, body);
break;
case org.apache.activemq.artemis.api.core.Message.OBJECT_TYPE:
writeObjectType(contents, messageCompressed, body);
break;
case org.apache.activemq.artemis.api.core.Message.STREAM_TYPE:
writeStreamType(contents, messageCompressed, body);
break;
case org.apache.activemq.artemis.api.core.Message.BYTES_TYPE:
writeBytesType(contents, messageCompressed, body);
break;
default:
writeDefaultType(contents, messageCompressed, body);
break;
}
}
// amq specific
coreMessage.putLongProperty(AMQ_MSG_ARRIVAL, messageSend.getArrival());
coreMessage.putLongProperty(AMQ_MSG_BROKER_IN_TIME, messageSend.getBrokerInTime());
final BrokerId[] brokers = messageSend.getBrokerPath();
if (brokers != null) {
putMsgBrokerPath(brokers, coreMessage);
}
final BrokerId[] cluster = messageSend.getCluster();
if (cluster != null) {
putMsgCluster(cluster, coreMessage);
}
coreMessage.putIntProperty(AMQ_MSG_COMMAND_ID, messageSend.getCommandId());
final String corrId = messageSend.getCorrelationId();
if (corrId != null) {
coreMessage.putStringProperty(JMS_CORRELATION_ID_PROPERTY, new SimpleString(corrId));
}
final DataStructure ds = messageSend.getDataStructure();
if (ds != null) {
putMsgDataStructure(ds, marshaller, coreMessage);
}
final String groupId = messageSend.getGroupID();
if (groupId != null) {
coreMessage.putStringProperty(AMQ_MSG_GROUP_ID, coreMessageObjectPools.getGroupIdStringSimpleStringPool().getOrCreate(groupId));
}
coreMessage.putIntProperty(AMQ_MSG_GROUP_SEQUENCE, messageSend.getGroupSequence());
final MessageId messageId = messageSend.getMessageId();
final ByteSequence midBytes = marshaller.marshal(messageId);
midBytes.compact();
coreMessage.putBytesProperty(AMQ_MSG_MESSAGE_ID, midBytes.data);
final ProducerId producerId = messageSend.getProducerId();
if (producerId != null) {
final ByteSequence producerIdBytes = marshaller.marshal(producerId);
producerIdBytes.compact();
coreMessage.putBytesProperty(AMQ_MSG_PRODUCER_ID, producerIdBytes.data);
}
final ByteSequence propBytes = messageSend.getMarshalledProperties();
if (propBytes != null) {
putMsgMarshalledProperties(propBytes, messageSend, coreMessage);
}
final ActiveMQDestination replyTo = messageSend.getReplyTo();
if (replyTo != null) {
putMsgReplyTo(replyTo, marshaller, coreMessage);
}
final String userId = messageSend.getUserID();
if (userId != null) {
coreMessage.putStringProperty(AMQ_MSG_USER_ID, new SimpleString(userId));
}
coreMessage.putBooleanProperty(AMQ_MSG_DROPPABLE, messageSend.isDroppable());
final ActiveMQDestination origDest = messageSend.getOriginalDestination();
if (origDest != null) {
putMsgOriginalDestination(origDest, marshaller, coreMessage);
}
return coreMessage;
}
Aggregations