当前位置: 首页>>代码示例>>Java>>正文


Java JMSProducer类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:21,代码来源:JmsPoolJMSContext.java

示例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());
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:21,代码来源:JmsPoolJMSProducerTest.java

示例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());
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:25,代码来源:JmsPoolJMSProducerTest.java

示例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());
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:21,代码来源:JmsPoolJMSProducerTest.java

示例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) {}
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:19,代码来源:JmsPoolJMSProducerTest.java

示例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) {}
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:19,代码来源:JmsPoolJMSProducerTest.java

示例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) {}
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:19,代码来源:JmsPoolJMSProducerTest.java

示例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);
    }
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:21,代码来源:MockJMSContext.java

示例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);
    }
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.transx,代码行数:17,代码来源:JMSContextImpl.java

示例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;
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:13,代码来源:JmsPoolJMSProducer.java

示例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;
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.transx,代码行数:12,代码来源:JMSProducerImpl.java

示例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));
    }
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:12,代码来源:JmsPoolJMSProducer.java

示例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;
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:10,代码来源:JmsPoolJMSProducer.java

示例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);
    }
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:11,代码来源:JmsPoolJMSProducer.java

示例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"));
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:15,代码来源:JmsPoolJMSProducerTest.java


注:本文中的javax.jms.JMSProducer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。