jms 消息的确认模式

三种

.Session.AUTO_ACKNOWLEDGE
                 CLIENT_ACKNOWLEDGE
                DUPS_OK_ACKNOWLEDGE

 

1、AUTO_ACKNOWLEDGE 是自动确认模式,不需客户端进行确认

服务器端:

    pubSession = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

 

2 、     CLIENT_ACKNOWLEDGE   客户端进行确认

       服务器端

                       conn.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);

     客户端

                public void onMessage(Message message) {

                           try{

                              message.acknowledge();

                                }catch (){

                                              如果在此期间出现异常,这个时候服务器端可能会保存这个消息,进行恢复后的重新发磅,因此可能导致消息的重复处理,所以这里可以进行一定的操作保证。。。  ,如undo ,回滚等操作

 

                                  }

                            。。。。。。。。。。。。进行消息 的处理

 

                  }

 

3                  DUPS_OK_ACKNOWLEDGE  允许重复消息,

 

This acknowledgment mode instructs the session to lazily acknowledge the delivery of messages. This is likely to result in the delivery of some duplicate messages if the JMS provider fails, so it should only be used by consumers that can tolerate duplicate messages. Use of this mode can reduce session overhead by minimizing the work the session does to prevent duplicates.

 google 翻译:

这确认模式指示会议懒洋洋地承认邮件的传递。 这可能导致一些重复的,如果JMS 提供者失败的讯息传递,因此它应该只用于消费者可以容忍重复的邮件。 使用这种模式可以减少工作的会议尽量减少会议的开销并防止重复。

 

DUPS_OK_ACKNOWLEDGE:允许副本的确认模式。一旦接收方应用程序的方法调用从处理消息处返回,会话对象就会确认消息的接收;而且允许重 复确认。在需要考虑资源使用时,这种模式非常有效。注意:如果你的应用程序无法处理重复的消息的话,你应该避免使用这种模式。如果发送消息的初始化尝试失 败,那么重复的消息可以被重新发送。

你可能感兴趣的:(工作,session,jms,服务器)