Java Examples for org.apache.activemq.advisory.AdvisorySupport
The following java examples will help you to understand the usage of org.apache.activemq.advisory.AdvisorySupport. These source code samples are taken from different open source projects.
Example 1
| Project: activemq-in-action-master File: Advisory.java View source code |
public static void main(String[] args) throws Exception {
Advisory advisory = new Advisory();
Session session = advisory.getSession();
for (String stock : args) {
ActiveMQDestination destination = (ActiveMQDestination) session.createTopic("STOCKS." + stock);
Destination consumerTopic = AdvisorySupport.getConsumerAdvisoryTopic(destination);
System.out.println("Subscribing to advisory " + consumerTopic);
MessageConsumer consumerAdvisory = session.createConsumer(consumerTopic);
consumerAdvisory.setMessageListener(new ConsumerAdvisoryListener());
Destination noConsumerTopic = AdvisorySupport.getNoTopicConsumersAdvisoryTopic(destination);
System.out.println("Subscribing to advisory " + noConsumerTopic);
MessageConsumer noConsumerAdvisory = session.createConsumer(noConsumerTopic);
noConsumerAdvisory.setMessageListener(new NoConsumerAdvisoryListener());
}
}Example 2
| Project: activemq-master File: TransportConnection.java View source code |
@Override
public Response processAddProducer(ProducerInfo info) throws Exception {
SessionId sessionId = info.getProducerId().getParentId();
ConnectionId connectionId = sessionId.getParentId();
TransportConnectionState cs = lookupConnectionState(connectionId);
if (cs == null) {
throw new IllegalStateException("Cannot add a producer to a connection that had not been registered: " + connectionId);
}
SessionState ss = cs.getSessionState(sessionId);
if (ss == null) {
throw new IllegalStateException("Cannot add a producer to a session that had not been registered: " + sessionId);
}
// Avoid replaying dup commands
if (!ss.getProducerIds().contains(info.getProducerId())) {
ActiveMQDestination destination = info.getDestination();
// call it from here with a null Destination value.
if (!AdvisorySupport.isAdvisoryTopic(destination)) {
if (getProducerCount(connectionId) >= connector.getMaximumProducersAllowedPerConnection()) {
throw new IllegalStateException("Can't add producer on connection " + connectionId + ": at maximum limit: " + connector.getMaximumProducersAllowedPerConnection());
}
}
broker.addProducer(cs.getContext(), info);
try {
ss.addProducer(info);
} catch (IllegalStateException e) {
broker.removeProducer(cs.getContext(), info);
}
}
return null;
}Example 3
| Project: ActiveMQ-HowTo-master File: AdvisoryConsumerApp.java View source code |
public void before() throws Exception {
connectionFactory = new ActiveMQConnectionFactory(connectionUri);
connection = connectionFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
monitored = session.createQueue("MyQueue");
destination = session.createTopic(AdvisorySupport.getConsumerAdvisoryTopic(monitored).getPhysicalName() + "," + AdvisorySupport.getProducerAdvisoryTopic(monitored).getPhysicalName());
advisoryConsumer = session.createConsumer(destination);
advisoryConsumer.setMessageListener(this);
connection.start();
}Example 4
| Project: apachecon-master File: ZonesBroker.java View source code |
@Override
public Destination addDestination(ConnectionContext context, ActiveMQDestination destination, boolean createIfTemporary) throws Exception {
if (!AdvisorySupport.isAdvisoryTopic(destination) && zoner.getManager().getZoneId(destination) == null) {
String pn = zoner.getManager().zoneDestination(context, destination);
LOG.debug("Zoning destination '{}' to '{}'", destination.getPhysicalName(), pn);
destination.setPhysicalName(pn);
}
return super.addDestination(context, destination, createIfTemporary);
}Example 5
| Project: activemq-artemis-master File: OpenWireConnection.java View source code |
public void addDestination(DestinationInfo info) throws Exception {
ActiveMQDestination dest = info.getDestination();
if (dest.isQueue()) {
SimpleString qName = new SimpleString(dest.getPhysicalName());
QueueBinding binding = (QueueBinding) server.getPostOffice().getBinding(qName);
if (binding == null) {
if (dest.isTemporary()) {
internalSession.createQueue(qName, qName, RoutingType.ANYCAST, null, dest.isTemporary(), false);
} else {
ConnectionInfo connInfo = getState().getInfo();
CheckType checkType = dest.isTemporary() ? CheckType.CREATE_NON_DURABLE_QUEUE : CheckType.CREATE_DURABLE_QUEUE;
server.getSecurityStore().check(qName, checkType, this);
server.checkQueueCreationLimit(getUsername());
server.createQueue(qName, RoutingType.ANYCAST, qName, connInfo == null ? null : SimpleString.toSimpleString(connInfo.getUserName()), null, true, false);
}
}
}
if (dest.isTemporary()) {
//Openwire needs to store the DestinationInfo in order to send
//Advisory messages to clients
this.state.addTempDestination(info);
}
if (!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);
}
}