简体   繁体   English

如何将持久性设置为 JMS 客户端?

[英]How to set Persistence to JMS client?

I set up a connection with Weblogic IBM Webpsphere MQ through JMS with using a secure channel using SSL.我使用使用 SSL 的安全通道通过 JMS 建立了与 Weblogic IBM Webpsphere MQ 的连接。 My application on Weblogic received message from MQ.我在 Weblogic 上的应用程序收到了来自 MQ 的消息。 Sending answer to reply queue.将答案发送到回复队列。 The response header is present MQMD, it fills java.响应头存在 MQMD,它填充 java.lang. In parameter Persistence JMS send value "1".在参数 Persistence JMS 中发送值“1”。 Other system need to received value "0" at Persistence.其他系统需要在 Persistence 接收值“0”。 How to set this parameter to java?如何将此参数设置为java? I guess that parameter is javax.jms.deliverymode.我猜这个参数是 javax.jms.deliverymode。 But how to set it i don't know.但是不知道怎么设置。

Anyway thank you for help.无论如何谢谢你的帮助。

The corresponding property on JMS is the delivery mode (Int parameter to be set) to set Persistent and non persistent messages. JMS上对应的属性是传递方式(要设置Int参数)来设置持久化和非持久化消息。

You can refer this URL from IBM for details您可以从IBM参考此 URL 以获取详细信息

You should try like this:你应该这样尝试:

public String sendMessage(ConnectionFactory connectionFactory,
                      Destination destination,
                      Destination jmsReplyTo,
                      CorrelationType correlationType,
                      CallOptions<String> callOptions,
                      String rqUid,
                      JMSAbstract transport) throws JMSException {
Connection connection = null;
Session session = null;
MessageProducer producer = null;

try {

    connection = connectionFactory.createConnection();
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    producer = session.createProducer(destination);

    // Set JMS DeliverMode (1/2)
    producer.setDeliveryMode(1);

    // create message
    Message message = createTextMessage(session, jmsReplyTo, correlationType, callOptions, rqUid, transport);

    // send message
    producer.send(message);

    return correlationType.getCorrelationId(message);

    } finally {
        closeResource(connection, session, null, producer, rqUid);
    }
}

It`s just a java example.这只是一个java示例。 Also you can set persistence flag in Queue configuration in IBM WebSphere.您也可以在 IBM WebSphere 的队列配置中设置持久性标志。 I mean MQQueue have method setPersistence.我的意思是 MQQueue 有方法 setPersistence。 If you using IBM java objects in your project, you can set persistence by calling that method:如果您在项目中使用 IBM java 对象,则可以通过调用该方法来设置持久性:

MQQueue mqQueue = new MQQueue("QueueName");
mqQueue.setPersistence(1);

I The answer of 0x5a4d is ok but better to use this like IBM best practices I 0x5a4d 的答案是可以的,但最好像 IBM 最佳实践一样使用它

//Persistentmode = 1 
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
//Persistentmode = 2 
producer.setDeliveryMode(DeliveryMode.PERSISTENT);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM