本文整理汇总了Java中javax.jms.JMSProducer类的典型用法代码示例。如果您正苦于以下问题:Java JMSProducer类的具体用法?Java JMSProducer怎么用?Java JMSProducer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JMSProducer类属于javax.jms包,在下文中一共展示了JMSProducer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createProducer
import javax.jms.JMSProducer; //导入依赖的package包/类
@Override
public JMSProducer createProducer() {
if (connectionRefCount.get() == 0) {
throw new IllegalStateRuntimeException("The Connection is closed");
}
try {
if (sharedProducer == null) {
synchronized (this) {
if (sharedProducer == null) {
sharedProducer = (JmsPoolMessageProducer) getSession().createProducer(null);
}
}
}
return new JmsPoolJMSProducer(getSession(), sharedProducer);
} catch (JMSException jmse) {
throw JMSExceptionSupport.createRuntimeException(jmse);
}
}
示例2: testStringBodyIsApplied
import javax.jms.JMSProducer; //导入依赖的package包/类
@Test
public void testStringBodyIsApplied() throws JMSException {
JMSProducer producer = context.createProducer();
final String bodyValue = "String-Value";
final AtomicBoolean bodyValidated = new AtomicBoolean();
MockJMSConnection connection = (MockJMSConnection) context.getConnection();
connection.addConnectionListener(new MockJMSDefaultConnectionListener() {
@Override
public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
assertEquals(bodyValue, message.getBody(String.class));
bodyValidated.set(true);
}
});
producer.send(JMS_DESTINATION, bodyValue);
assertTrue(bodyValidated.get());
}
示例3: testMapBodyIsApplied
import javax.jms.JMSProducer; //导入依赖的package包/类
@Test
public void testMapBodyIsApplied() throws JMSException {
JMSProducer producer = context.createProducer();
final Map<String, Object> bodyValue = new HashMap<String, Object>();
bodyValue.put("Value-1", "First");
bodyValue.put("Value-2", "Second");
final AtomicBoolean bodyValidated = new AtomicBoolean();
MockJMSConnection connection = (MockJMSConnection) context.getConnection();
connection.addConnectionListener(new MockJMSDefaultConnectionListener() {
@Override
public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
assertEquals(bodyValue, message.getBody(Map.class));
bodyValidated.set(true);
}
});
producer.send(JMS_DESTINATION, bodyValue);
assertTrue(bodyValidated.get());
}
示例4: testSerializableBodyIsApplied
import javax.jms.JMSProducer; //导入依赖的package包/类
@Test
public void testSerializableBodyIsApplied() throws JMSException {
JMSProducer producer = context.createProducer();
final UUID bodyValue = UUID.randomUUID();
final AtomicBoolean bodyValidated = new AtomicBoolean();
MockJMSConnection connection = (MockJMSConnection) context.getConnection();
connection.addConnectionListener(new MockJMSDefaultConnectionListener() {
@Override
public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
assertEquals(bodyValue, message.getBody(UUID.class));
bodyValidated.set(true);
}
});
producer.send(JMS_DESTINATION, bodyValue);
assertTrue(bodyValidated.get());
}
示例5: testRuntimeExceptionFromSendByteBody
import javax.jms.JMSProducer; //导入依赖的package包/类
@Test
public void testRuntimeExceptionFromSendByteBody() throws JMSException {
JMSProducer producer = context.createProducer();
MockJMSConnection connection = (MockJMSConnection) context.getConnection();
connection.addConnectionListener(new MockJMSDefaultConnectionListener() {
@Override
public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
throw new IllegalStateException("Send Failed");
}
});
try {
producer.send(context.createTemporaryQueue(), new byte[0]);
fail("Should have thrown an exception");
} catch (IllegalStateRuntimeException isre) {}
}
示例6: testRuntimeExceptionFromSendMapBody
import javax.jms.JMSProducer; //导入依赖的package包/类
@Test
public void testRuntimeExceptionFromSendMapBody() throws JMSException {
JMSProducer producer = context.createProducer();
MockJMSConnection connection = (MockJMSConnection) context.getConnection();
connection.addConnectionListener(new MockJMSDefaultConnectionListener() {
@Override
public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
throw new IllegalStateException("Send Failed");
}
});
try {
producer.send(context.createTemporaryQueue(), Collections.<String, Object>emptyMap());
fail("Should have thrown an exception");
} catch (IllegalStateRuntimeException isre) {}
}
示例7: testRuntimeExceptionFromSendStringBody
import javax.jms.JMSProducer; //导入依赖的package包/类
@Test
public void testRuntimeExceptionFromSendStringBody() throws JMSException {
JMSProducer producer = context.createProducer();
MockJMSConnection connection = (MockJMSConnection) context.getConnection();
connection.addConnectionListener(new MockJMSDefaultConnectionListener() {
@Override
public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
throw new IllegalStateException("Send Failed");
}
});
try {
producer.send(context.createTemporaryQueue(), "test");
fail("Should have thrown an exception");
} catch (IllegalStateRuntimeException isre) {}
}
示例8: createProducer
import javax.jms.JMSProducer; //导入依赖的package包/类
@Override
public JMSProducer createProducer() {
if (connectionRefCount.get() == 0) {
throw new IllegalStateRuntimeException("The Connection is closed");
}
try {
if (sharedProducer == null) {
synchronized (this) {
if (sharedProducer == null) {
sharedProducer = (MockJMSMessageProducer) getSession().createProducer(null);
}
}
}
return new MockJMSProducer(getSession(), sharedProducer);
} catch (JMSException jmse) {
throw JMSExceptionSupport.createRuntimeException(jmse);
}
}
示例9: createProducer
import javax.jms.JMSProducer; //导入依赖的package包/类
@Override
public JMSProducer createProducer() {
try {
if (sharedProducer == null) {
synchronized (this) {
if (sharedProducer == null) {
sharedProducer = getSession().createProducer(null);
}
}
}
return new JMSProducerImpl(this, sharedProducer);
} catch (JMSException jmse) {
throw Utils.convertToRuntimeException(jmse);
}
}
示例10: send
import javax.jms.JMSProducer; //导入依赖的package包/类
@Override
public JMSProducer send(Destination destination, byte[] body) {
try {
BytesMessage message = session.createBytesMessage();
message.writeBytes(body);
doSend(destination, message);
} catch (JMSException jmse) {
throw JMSExceptionSupport.createRuntimeException(jmse);
}
return this;
}
示例11: send
import javax.jms.JMSProducer; //导入依赖的package包/类
@Override
public JMSProducer send(Destination destination, Serializable body) {
try {
ObjectMessage message = context.createObjectMessage();
message.setObject(body);
doSend(destination, message);
} catch (JMSException jmse) {
throw Utils.convertToRuntimeException(jmse);
}
return this;
}
示例12: setDeliveryMode
import javax.jms.JMSProducer; //导入依赖的package包/类
@Override
public JMSProducer setDeliveryMode(int deliveryMode) {
switch (deliveryMode) {
case DeliveryMode.PERSISTENT:
case DeliveryMode.NON_PERSISTENT:
this.deliveryMode = deliveryMode;
return this;
default:
throw new JMSRuntimeException(String.format("Invalid DeliveryMode specified: %d", deliveryMode));
}
}
示例13: setPriority
import javax.jms.JMSProducer; //导入依赖的package包/类
@Override
public JMSProducer setPriority(int priority) {
if (priority < 0 || priority > 9) {
throw new JMSRuntimeException(String.format("Priority value given {%d} is out of range (0..9)", priority));
}
this.priority = priority;
return this;
}
示例14: setObjectProperty
import javax.jms.JMSProducer; //导入依赖的package包/类
private JMSProducer setObjectProperty(String name, Object value) {
try {
checkPropertyNameIsValid(name, true);
checkValidObject(value);
messageProperties.put(name, value);
return this;
} catch (JMSException e) {
throw JMSExceptionSupport.createRuntimeException(e);
}
}
示例15: testGetPropertyNames
import javax.jms.JMSProducer; //导入依赖的package包/类
@Test
public void testGetPropertyNames() {
JMSProducer producer = context.createProducer();
producer.setProperty("Property_1", "1");
producer.setProperty("Property_2", "2");
producer.setProperty("Property_3", "3");
assertEquals(3, producer.getPropertyNames().size());
assertTrue(producer.getPropertyNames().contains("Property_1"));
assertTrue(producer.getPropertyNames().contains("Property_2"));
assertTrue(producer.getPropertyNames().contains("Property_3"));
}