本文整理汇总了Java中javax.jms.Destination类的典型用法代码示例。如果您正苦于以下问题:Java Destination类的具体用法?Java Destination怎么用?Java Destination使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Destination类属于javax.jms包,在下文中一共展示了Destination类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: putTopic
import javax.jms.Destination; //导入依赖的package包/类
private void putTopic(List<String> events) throws Exception {
ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME,
PASSWORD, BROKER_BIND_URL);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(true,
Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createTopic(DESTINATION_NAME);
MessageProducer producer = session.createProducer(destination);
for (String event : events) {
TextMessage message = session.createTextMessage();
message.setText(event);
producer.send(message);
}
session.commit();
session.close();
connection.close();
}
示例2: sendMessage
import javax.jms.Destination; //导入依赖的package包/类
/**
* 使用jmsTemplate的send/MessageCreator()发送Map类型的消息并在Message中附加属性用于消息过滤.
*/
private void sendMessage(final User user, Destination destination) {
jmsTemplate.send(destination, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
MapMessage message = session.createMapMessage();
message.setString("userName", user.getName());
message.setString("email", user.getEmail());
message.setStringProperty("objectType", "user");
return message;
}
});
}
示例3: send
import javax.jms.Destination; //导入依赖的package包/类
public static void send(String queueName, String text, int delayMillis) {
EXECUTOR.submit(() -> {
try {
logger.info("*** artificial delay {}: {}", queueName, delayMillis);
Thread.sleep(delayMillis);
Connection connection = getConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(queueName);
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage message = session.createTextMessage(text);
producer.send(message);
logger.info("*** sent message {}: {}", queueName, text);
session.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
示例4: JmsPoolMessageProducer
import javax.jms.Destination; //导入依赖的package包/类
public JmsPoolMessageProducer(JmsPoolSession session, MessageProducer messageProducer, Destination destination, boolean shared) throws JMSException {
this.session = session;
this.messageProducer = messageProducer;
this.destination = destination;
this.shared = shared;
this.anonymousProducer = destination == null;
this.deliveryMode = messageProducer.getDeliveryMode();
this.disableMessageID = messageProducer.getDisableMessageID();
this.disableMessageTimestamp = messageProducer.getDisableMessageTimestamp();
this.priority = messageProducer.getPriority();
this.timeToLive = messageProducer.getTimeToLive();
if (session.isJMSVersionSupported(2, 0)) {
this.deliveryDelay = messageProducer.getDeliveryDelay();
}
}
示例5: putQueue
import javax.jms.Destination; //导入依赖的package包/类
private void putQueue(List<String> events) throws Exception {
ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME,
PASSWORD, BROKER_BIND_URL);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(true,
Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(DESTINATION_NAME);
MessageProducer producer = session.createProducer(destination);
for (String event : events) {
TextMessage message = session.createTextMessage();
message.setText(event);
producer.send(message);
}
session.commit();
session.close();
connection.close();
}
示例6: SimpleFilter
import javax.jms.Destination; //导入依赖的package包/类
public SimpleFilter(String name, String sorgenteMessaggi, String destinazioneMessaggi,
String connectionFactory, SimpleMessageFilter mf, int maxDelay) {
this.name = name;
this.messageSource = (Destination) JndiUtil.getInstance().jndiLookup(sorgenteMessaggi);
this.messageDestination = (Destination) JndiUtil.getInstance().jndiLookup(destinazioneMessaggi);
this.connectionFactory = (ConnectionFactory) JndiUtil.getInstance().jndiLookup(connectionFactory);
this.messageFilter = mf;
this.maxDelay = maxDelay;
/* crea un consumatore su sorgenteMessaggi:
* girera' messaggi a questo oggetto (this) */
this.consumer =
new SimpleAsynchConsumer("Consumatore messaggi per " + this.name,
this.messageSource, this.connectionFactory, this, 10);
logger.info("Creato consumatore: " + consumer.toString());
/* crea un produttore su destinazioneMessaggi */
this.producer = new SimpleProducer("Produttore messaggi per " + this.name,
this.messageDestination, this.connectionFactory, 10);
logger.info("Creato produttore: " + producer.toString());
this.messagesReceived = 0;
this.cancelled = false;
}
示例7: doSendBinaryMessage
import javax.jms.Destination; //导入依赖的package包/类
private void doSendBinaryMessage( final Session session, final Destination destination,
final byte[] bytes,
final Map<String, ?> properties ) throws JMSException {
try {
BytesMessage message = session.createBytesMessage();
message.writeBytes(bytes);
if (properties != null) {
// Note: Setting any properties (including JMS fields) using
// setObjectProperty might not be supported by all providers
// Tested with: ActiveMQ
for (final Entry<String, ?> property : properties.entrySet()) {
message.setObjectProperty(property.getKey(), property.getValue());
}
}
final MessageProducer producer = session.createProducer(destination);
producer.send(message);
} finally {
releaseSession(false);
}
}
示例8: doSend
import javax.jms.Destination; //导入依赖的package包/类
private void doSend(Destination destination, Message message) throws JMSException {
if (message == null) {
throw new MessageFormatException("Message must not be null");
}
for (Map.Entry<String, Object> entry : messageProperties.entrySet()) {
message.setObjectProperty(entry.getKey(), entry.getValue());
}
if (correlationId != null) {
message.setJMSCorrelationID(correlationId);
}
if (correlationIdBytes != null) {
message.setJMSCorrelationIDAsBytes(correlationIdBytes);
}
if (type != null) {
message.setJMSType(type);
}
if (replyTo != null) {
message.setJMSReplyTo(replyTo);
}
session.send(producer, destination, message, deliveryMode, priority, timeToLive, disableMessageId, disableTimestamp, deliveryDelay, completionListener);
}
示例9: testReception
import javax.jms.Destination; //导入依赖的package包/类
private void testReception(
final TestClass i,
final Destination destination, final ThrowingConsumer<Destination> destinationCheck
) throws Exception {
final Connection connection = i.connectionFactory.createConnection();
assertNotNull(connection);
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertNotNull(session);
final MessageProducer producer = session.createProducer(destination);
assertNotNull(producer);
final TextMessage message = session.createTextMessage();
assertNotNull(message);
message.setText("I am IronMan");
producer.send(message);
final List<ReceivedJmsMessage> messages = i.testQueue.drainReceivedMessages();
assertEquals(1, messages.size());
final ReceivedJmsMessage receivedMessage = messages.get(0);
destinationCheck.accept(receivedMessage.getDestination());
assertTrue(receivedMessage.getJmsMessage() instanceof TextMessage);
final TextMessage receivedTextMessage = (TextMessage) receivedMessage.getJmsMessage();
assertEquals("I am IronMan", receivedTextMessage.getText());
}
示例10: getMessageProducer
import javax.jms.Destination; //导入依赖的package包/类
private MessageProducer getMessageProducer(Destination destination) throws JMSException {
MessageProducer result = null;
if (useAnonymousProducers) {
result = safeGetSessionHolder().getOrCreateProducer();
} else {
result = getInternalSession().createProducer(destination);
}
return result;
}
示例11: createConsumer
import javax.jms.Destination; //导入依赖的package包/类
@Override
public JMSConsumer createConsumer(Destination destination) {
try {
return startIfNeeded(new JmsPoolJMSConsumer((JmsPoolMessageConsumer) getSession().createConsumer(destination)));
} catch (JMSException jmse) {
throw JMSExceptionSupport.createRuntimeException(jmse);
}
}
示例12: testConsumerProducerWithAutoAck
import javax.jms.Destination; //导入依赖的package包/类
@Parameters({ "broker-port"})
@Test
public void testConsumerProducerWithAutoAck(String port) throws Exception {
String queueName = "testConsumerProducerWithAutoAck";
InitialContext initialContextForQueue = ClientHelper
.getInitialContextBuilder("admin", "admin", "localhost", port)
.withQueue(queueName)
.build();
ConnectionFactory connectionFactory
= (ConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
Connection connection = connectionFactory.createConnection();
connection.start();
// publish 100 messages
Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = producerSession.createQueue(queueName);
MessageProducer producer = producerSession.createProducer(queue);
int numberOfMessages = 100;
for (int i = 0; i < numberOfMessages; i++) {
producer.send(producerSession.createTextMessage("Test message " + i));
}
producerSession.close();
// Consume published messages
Session subscriberSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination subscriberDestination = (Destination) initialContextForQueue.lookup(queueName);
MessageConsumer consumer = subscriberSession.createConsumer(subscriberDestination);
for (int i = 0; i < numberOfMessages; i++) {
Message message = consumer.receive(5000);
Assert.assertNotNull(message, "Message #" + i + " was not received");
}
connection.close();
}
示例13: setup
import javax.jms.Destination; //导入依赖的package包/类
@Before
public void setup() throws Exception {
beforeSetup();
connectionFactory = mock(ConnectionFactory.class);
connection = mock(Connection.class);
session = mock(Session.class);
queue = mock(Queue.class);
topic = mock(Topic.class);
messageConsumer = mock(MessageConsumer.class);
message = mock(TextMessage.class);
when(message.getPropertyNames()).thenReturn(new Enumeration<Object>() {
@Override
public boolean hasMoreElements() {
return false;
}
@Override
public Object nextElement() {
throw new UnsupportedOperationException();
}
});
when(message.getText()).thenReturn(TEXT);
when(connectionFactory.createConnection(USERNAME, PASSWORD)).thenReturn(connection);
when(connection.createSession(true, Session.SESSION_TRANSACTED)).thenReturn(session);
when(session.createQueue(destinationName)).thenReturn(queue);
when(session.createConsumer(any(Destination.class), anyString())).thenReturn(messageConsumer);
when(messageConsumer.receiveNoWait()).thenReturn(message);
when(messageConsumer.receive(anyLong())).thenReturn(message);
destinationName = DESTINATION_NAME;
destinationType = JMSDestinationType.QUEUE;
destinationLocator = JMSDestinationLocator.CDI;
messageSelector = SELECTOR;
batchSize = 10;
pollTimeout = 500L;
context = new Context();
converter = new DefaultJMSMessageConverter.Builder().build(context);
event = converter.convert(message).iterator().next();
userName = Optional.of(USERNAME);
password = Optional.of(PASSWORD);
afterSetup();
}
示例14: send
import javax.jms.Destination; //导入依赖的package包/类
@Override
public void send(Destination destination, Message message, int deliveryMode, int priority,
long timeToLive) throws JMSException {
Span span = TracingMessageUtils.buildAndInjectSpan(destination, message, tracer);
try {
messageProducer.send(destination, message, deliveryMode, priority, timeToLive);
} catch (Throwable e) {
SpanJmsDecorator.onError(e, span);
throw e;
} finally {
span.finish();
}
}
示例15: formatAddress
import javax.jms.Destination; //导入依赖的package包/类
@Override
protected String formatAddress(Destination destination) {
if (destination == null) {
return null;
}
if (!(destination instanceof ActiveMQDestination)) {
throw new InvalidParameterException("Destination must be a Core destination, was " + destination.getClass());
}
String address = ((ActiveMQDestination) destination).getName();
return dropDestinationPrefix(address);
}