本文整理汇总了Java中org.apache.activemq.command.Message类的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于org.apache.activemq.command包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertQueues
import org.apache.activemq.command.Message; //导入依赖的package包/类
/**
* Determine the destinations associated with this message
* Will be one destination for a Queue message or 1 or more for a Topic
*
* @param message
* @return
* @throws Exception
*/
private QueuesType convertQueues(final Message message) throws Exception {
if (store == null || message.getDestination().isQueue()) {
return QueuesType.builder()
.withQueue(QueueType.builder()
.withName(message.getDestination().getPhysicalName()).build())
.build();
} else {
final QueuesType.Builder<Void> queuesBuilder = QueuesType.builder();
KahaDBUtil.getUnackedSubscriptions(store, message).forEach(sub -> {
queuesBuilder.addQueue(QueueType.builder().withName(
ActiveMQDestination.createQueueNameForDurableSubscription(
true, sub.getClientId(), sub.getSubcriptionName())).build());
});
return queuesBuilder.build();
}
}
示例2: publish
import org.apache.activemq.command.Message; //导入依赖的package包/类
@Override
public void publish(final Message message, final KafkaTemplate<String, byte[]> kafkaTemplate) {
try {
final byte[] effectivePayload = message.getContent().getData();
final String sourceTopic = message.getDestination().getPhysicalName();
final String destTopic = this.getDestTopic(sourceTopic);
kafkaTemplate.send(destTopic, effectivePayload);
} catch (final Throwable t) {
LOG.error("Exception occured", t);
}
}
示例3: updateMessage
import org.apache.activemq.command.Message; //导入依赖的package包/类
@Override
public void updateMessage(Message message) throws IOException {
if (throwExceptionOnUpdate) {
if (numBeforeException > 0) {
numBeforeException--;
super.updateMessage(message);
} else {
// lets only do it once so we can validate transient store failure
throwExceptionOnUpdate = false;
//A message that has never been delivered will hit this exception
throw new IOException("Hit our simulated exception writing the update to disk");
}
} else {
super.updateMessage(message);
}
}
示例4: receiveMessage
import org.apache.activemq.command.Message; //导入依赖的package包/类
public Message receiveMessage(StubConnection connection, long timeout) throws InterruptedException {
while (true) {
Object o = connection.getDispatchQueue().poll(timeout, TimeUnit.MILLISECONDS);
if (o == null) {
return null;
}
if (o instanceof MessageDispatch) {
MessageDispatch dispatch = (MessageDispatch) o;
if (dispatch.getMessage() == null) {
return null;
}
dispatch.setMessage(dispatch.getMessage().copy());
dispatch.getMessage().setRedeliveryCounter(dispatch.getRedeliveryCounter());
return dispatch.getMessage();
}
}
}
示例5: createBroker
import org.apache.activemq.command.Message; //导入依赖的package包/类
@Override
protected BrokerService createBroker() throws Exception {
BrokerService answer = new BrokerService();
answer.setPersistent(false);
answer.setMessageAuthorizationPolicy(new MessageAuthorizationPolicy() {
@Override
public boolean isAllowedToConsume(ConnectionContext context, Message message) {
try {
Object value = message.getProperty("myHeader");
return "abc".equals(value);
} catch (IOException e) {
System.out.println("Caught: " + e);
e.printStackTrace();
return false;
}
}
});
answer.addConnector(bindAddress);
return answer;
}
示例6: retryMessage
import org.apache.activemq.command.Message; //导入依赖的package包/类
/**
* Moves a message back to its original destination
*/
public boolean retryMessage(String messageId) throws Exception {
Queue queue = (Queue) destination;
QueueMessageReference ref = queue.getMessage(messageId);
Message rc = ref.getMessage();
if (rc != null) {
ActiveMQDestination originalDestination = rc.getOriginalDestination();
if (originalDestination != null) {
ConnectionContext context = BrokerSupport.getConnectionContext(broker.getContextBroker());
return queue.moveMessageTo(context, ref, originalDestination);
}
else {
throw new JMSException("No original destination for message: "+ messageId);
}
}
else {
throw new JMSException("Could not find message: "+ messageId);
}
}
示例7: send
import org.apache.activemq.command.Message; //导入依赖的package包/类
@Override
public void send(ProducerBrokerExchange exchange, Message message) throws Exception {
if (exchange != null && exchange.getProducerState() != null && exchange.getProducerState().getInfo() != null) {
ProducerInfo info = exchange.getProducerState().getInfo();
if (info.getDestination() == null && info.getProducerId() != null) {
ObjectName objectName = BrokerMBeanSupport.createProducerName(brokerObjectName, exchange.getConnectionContext().getClientId(), info);
ProducerView view = this.dynamicDestinationProducers.get(objectName);
if (view != null) {
ActiveMQDestination dest = message.getDestination();
if (dest != null) {
view.setLastUsedDestinationName(dest);
}
}
}
}
super.send(exchange, message);
}
示例8: send
import org.apache.activemq.command.Message; //导入依赖的package包/类
@Override
public void send(ProducerBrokerExchange producerExchange, final Message messageSend) throws Exception {
ActiveMQDestination activeMQDestination = messageSend.getDestination();
if (!interceptorMap.isEmpty() && activeMQDestination != null) {
Set<MessageInterceptor> set = interceptorMap.get(activeMQDestination);
if (set != null && !set.isEmpty()) {
for (MessageInterceptor mi : set) {
mi.intercept(producerExchange, messageSend);
}
} else {
super.send(producerExchange, messageSend);
}
} else {
super.send(producerExchange, messageSend);
}
}
示例9: send
import org.apache.activemq.command.Message; //导入依赖的package包/类
public void send(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception {
final ConnectionContext context = producerExchange.getConnectionContext();
String userID = context.getUserName();
if (isUseAuthenticatePrincipal()) {
SecurityContext securityContext = context.getSecurityContext();
if (securityContext != null) {
Set<?> principals = securityContext.getPrincipals();
if (principals != null) {
for (Object candidate : principals) {
if (candidate instanceof UserPrincipal) {
userID = ((UserPrincipal)candidate).getName();
break;
}
}
}
}
}
messageSend.setUserID(userID);
super.send(producerExchange, messageSend);
}
示例10: doResend
import org.apache.activemq.command.Message; //导入依赖的package包/类
public static void doResend(final ConnectionContext context, Message originalMessage, ActiveMQDestination deadLetterDestination, boolean copy) throws Exception {
Message message = copy ? originalMessage.copy() : originalMessage;
message.setOriginalDestination(message.getDestination());
message.setOriginalTransactionId(message.getTransactionId());
message.setDestination(deadLetterDestination);
message.setTransactionId(null);
message.setMemoryUsage(null);
message.setRedeliveryCounter(0);
boolean originalFlowControl = context.isProducerFlowControl();
try {
context.setProducerFlowControl(false);
ProducerInfo info = new ProducerInfo();
ProducerState state = new ProducerState(info);
ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
producerExchange.setProducerState(state);
producerExchange.setMutable(true);
producerExchange.setConnectionContext(context);
context.getBroker().send(producerExchange, message);
} finally {
context.setProducerFlowControl(originalFlowControl);
}
}
示例11: addMessage
import org.apache.activemq.command.Message; //导入依赖的package包/类
/**
* @param message
* @throws IOException
*/
void addMessage(ConnectionContext context, final MessageStore destination, final Message message)
throws IOException {
if (message.getTransactionId() != null) {
if (message.getTransactionId().isXATransaction() || theStore.isConcurrentStoreAndDispatchTransactions() == false) {
destination.addMessage(context, message);
} else {
Tx tx = getTx(message.getTransactionId());
tx.add(new AddMessageCommand(context) {
@Override
public Message getMessage() {
return message;
}
@Override
public Future<Object> run(ConnectionContext ctx) throws IOException {
destination.addMessage(ctx, message);
return AbstractMessageStore.FUTURE;
}
});
}
} else {
destination.addMessage(context, message);
}
}
示例12: onDispatch
import org.apache.activemq.command.Message; //导入依赖的package包/类
protected void onDispatch(final MessageReference node, final Message message) {
Destination nodeDest = (Destination) node.getRegionDestination();
if (nodeDest != null) {
if (node != QueueMessageReference.NULL_MESSAGE) {
nodeDest.getDestinationStatistics().getDispatched().increment();
nodeDest.getDestinationStatistics().getInflight().increment();
LOG.trace("{} dispatched: {} - {}, dispatched: {}, inflight: {}", new Object[]{ info.getConsumerId(), message.getMessageId(), message.getDestination(), dispatchCounter, dispatched.size() });
}
}
if (info.isDispatchAsync()) {
try {
dispatchPending();
} catch (IOException e) {
context.getConnection().serviceExceptionAsync(e);
}
}
}
示例13: createMessageDispatch
import org.apache.activemq.command.Message; //导入依赖的package包/类
/**
* @param node
* @param message
* @return MessageDispatch
*/
protected MessageDispatch createMessageDispatch(MessageReference node, Message message) {
MessageDispatch md = new MessageDispatch();
md.setConsumerId(info.getConsumerId());
if (node == QueueMessageReference.NULL_MESSAGE) {
md.setMessage(null);
md.setDestination(null);
} else {
Destination regionDestination = (Destination) node.getRegionDestination();
md.setDestination(regionDestination.getActiveMQDestination());
md.setMessage(message);
md.setRedeliveryCounter(node.getRedeliveryCounter());
}
return md;
}
示例14: send
import org.apache.activemq.command.Message; //导入依赖的package包/类
/**
*
*/
public void send(ProducerBrokerExchange producerExchange, Message message) throws Exception {
ActiveMQDestination destination = message.getDestination();
if (destination.isComposite()) {
ActiveMQDestination[] destinations = destination.getCompositeDestinations();
for (int i = 0; i < destinations.length; i++) {
if (i != 0) {
message = message.copy();
message.setMemoryUsage(null);
}
message.setOriginalDestination(destination);
message.setDestination(destinations[i]);
next.send(producerExchange, message);
}
} else {
next.send(producerExchange, message);
}
}
示例15: addMessageLast
import org.apache.activemq.command.Message; //导入依赖的package包/类
@Override
public synchronized void addMessageLast(MessageReference node) throws Exception {
if (node != null) {
Message msg = node.getMessage();
if (isStarted()) {
if (!msg.isPersistent()) {
nonPersistent.addMessageLast(node);
}
}
if (msg.isPersistent()) {
Destination dest = (Destination) msg.getRegionDestination();
TopicStorePrefetch tsp = topics.get(dest);
if (tsp != null) {
tsp.addMessageLast(node);
if (prioritizedMessages && immediatePriorityDispatch && tsp.isPaging()) {
if (msg.getPriority() > tsp.getLastRecoveredPriority()) {
tsp.recoverMessage(node.getMessage(), true);
LOG.trace("cached high priority ({} message: {}, current paged batch priority: {}, cache size: {}", new Object[]{ msg.getPriority(), msg.getMessageId(), tsp.getLastRecoveredPriority(), tsp.batchList.size()});
}
}
}
}
}
}