use of javax.jms.Destination in project spring-framework by spring-projects.
the class SimpleJmsHeaderMapperTests method jmsReplyToMappedFromHeader.
// Outbound mapping
@Test
public void jmsReplyToMappedFromHeader() throws JMSException {
Destination replyTo = new Destination() {
};
Message<String> message = initBuilder().setHeader(JmsHeaders.REPLY_TO, replyTo).build();
javax.jms.Message jmsMessage = new StubTextMessage();
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNotNull(jmsMessage.getJMSReplyTo());
assertSame(replyTo, jmsMessage.getJMSReplyTo());
}
use of javax.jms.Destination in project spring-framework by spring-projects.
the class SimpleJmsHeaderMapperTests method attemptToWriteDisallowedReplyToPropertyIsNotFatal.
@Test
public void attemptToWriteDisallowedReplyToPropertyIsNotFatal() throws JMSException {
Message<String> message = initBuilder().setHeader(JmsHeaders.REPLY_TO, new Destination() {
}).setHeader("foo", "bar").build();
javax.jms.Message jmsMessage = new StubTextMessage() {
@Override
public void setJMSReplyTo(Destination replyTo) throws JMSException {
throw new JMSException("illegal property");
}
};
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNull(jmsMessage.getJMSReplyTo());
assertNotNull(jmsMessage.getStringProperty("foo"));
assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
use of javax.jms.Destination in project tech by ffyyhh995511.
the class RequestProcessor method init.
public void init() throws JMSException {
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, "tcp://127.0.0.1:61616");
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(Boolean.FALSE, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("RequestQueue");
// 消息消费(接收)者
consumer = session.createConsumer(destination);
}
use of javax.jms.Destination in project qpid by apache.
the class Agent method setConnection.
/**
* Connect the Agent to the AMQP cloud.
* <p>
* This is an extension to the standard QMF2 API allowing the user to specify address options in order to allow
* finer control over the Agent's ingest queue, such as an explicit name, non-default size or durability.
*
* @param conn a javax.jms.Connection.
* @param addressOptions options String giving finer grained control of the receiver queue.
* <p>
* As an example the following gives the Agent's ingest queue the name test-agent, size = 500000000 and ring policy.
* <pre>
* " ; {link: {name:'test-agent', x-declare: {arguments: {'qpid.policy_type': ring, 'qpid.max_size': 500000000}}}}"
* </pre>
*/
public final void setConnection(final Connection conn, final String addressOptions) throws QmfException {
// to the same Agent instance at the same time.
synchronized (this) {
if (_connection != null) {
throw new QmfException("Multiple connections per Agent is not supported");
}
_connection = conn;
}
if (_name == null || _vendor == null || _product == null) {
throw new QmfException("The vendor, product or name is not set");
}
setValue("_epoch", _epoch);
setValue("_heartbeat_interval", _heartbeatInterval);
setValue("_name", _name);
setValue("_product", _product);
setValue("_vendor", _vendor);
setValue("_instance", _instance);
try {
_asyncSession = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
_syncSession = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create a Destination for the QMF direct address, mainly used for request/response
String directBase = "qmf." + _domain + ".direct";
_quotedDirectBase = "'" + directBase + "'";
_directAddress = _syncSession.createQueue(directBase);
// Create a Destination for the QMF topic address used to broadcast Events & Heartbeats.
String topicBase = "qmf." + _domain + ".topic";
_quotedTopicBase = "'" + topicBase + "'";
_topicAddress = _syncSession.createQueue(topicBase);
// Create an unidentified MessageProducer for sending to various destinations.
_producer = _syncSession.createProducer(null);
// TODO it should be possible to bind _locateConsumer, _mainConsumer and _aliasConsumer to the
// same queue if I can figure out the correct AddressString to use, probably not a big deal though.
// Set up MessageListener on the Agent Locate Address
Destination locateAddress = _asyncSession.createQueue(topicBase + "/console.request.agent_locate");
_locateConsumer = _asyncSession.createConsumer(locateAddress);
_locateConsumer.setMessageListener(this);
// Set up MessageListener on the Agent address
String address = directBase + "/" + _name + addressOptions;
Destination agentAddress = _asyncSession.createQueue(address);
_mainConsumer = _asyncSession.createConsumer(agentAddress);
_mainConsumer.setMessageListener(this);
// alias address rather than the discovered address when talking to the broker ManagementAgent.
if (_product.equals("qpidd")) {
String alias = directBase + "/broker";
_log.info("Creating address {} as an alias address for the broker Agent", alias);
Destination aliasAddress = _asyncSession.createQueue(alias);
_aliasConsumer = _asyncSession.createConsumer(aliasAddress);
_aliasConsumer.setMessageListener(this);
}
_connection.start();
// Schedule a Heartbeat every _heartbeatInterval seconds sending the first one immediately
_timer = new Timer(true);
_timer.schedule(new Heartbeat(), 0, _heartbeatInterval * 1000);
} catch (JMSException jmse) {
// If we can't create the QMF Destinations there's not much else we can do
_log.info("JMSException {} caught in setConnection()", jmse.getMessage());
throw new QmfException("Failed to create sessions or destinations " + jmse.getMessage());
}
}
use of javax.jms.Destination in project qpid by apache.
the class Console method invokeMethod.
/**
* Invoke the named method on the named Agent.
* <p>
* Intended to by called by the AgentProxy. Shouldn't generally be called directly by Console applications.
*
* @param agent the Agent to invoke the method on.
* @param content an unordered set of key/value pairs comprising the method arguments.
* @param replyHandle the correlation handle used to tie asynchronous method requests with responses
* @param timeout the time to wait for a reply from the Agent, a value of -1 means use the default timeout
* @return the method response Arguments in Map form
*/
public MethodResult invokeMethod(final Agent agent, final Map<String, Object> content, final String replyHandle, int timeout) throws QmfException {
if (!agent.isActive()) {
throw new QmfException("Called invokeMethod() with inactive agent");
}
String agentName = agent.getName();
timeout = (timeout < 1) ? _replyTimeout : timeout;
try {
Destination destination = (replyHandle == null) ? _replyAddress : _asyncReplyAddress;
MapMessage request = _syncSession.createMapMessage();
request.setJMSReplyTo(destination);
request.setJMSCorrelationID(replyHandle);
request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
request.setStringProperty("method", "request");
request.setStringProperty("qmf.opcode", "_method_request");
request.setStringProperty("qpid.subject", agentName);
for (Map.Entry<String, Object> entry : content.entrySet()) {
request.setObject(entry.getKey(), entry.getValue());
}
// it would be somewhat unfortunate if their response got interleaved with ours!!
synchronized (this) {
_requester.send(request);
if (replyHandle == null) {
// If this is a synchronous request get the response
Message response = _responder.receive(timeout * 1000);
if (response == null) {
_log.info("No response received in invokeMethod()");
throw new QmfException("No response received for Console.invokeMethod()");
}
MethodResult result = new MethodResult(AMQPMessage.getMap(response));
QmfException exception = result.getQmfException();
if (exception != null) {
throw exception;
}
return result;
}
}
// If this is an asynchronous request return without waiting for a response
return null;
} catch (JMSException jmse) {
_log.info("JMSException {} caught in invokeMethod()", jmse.getMessage());
throw new QmfException(jmse.getMessage());
}
}
Aggregations