`
aty
  • 浏览: 35713 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Session.AUTO_ACKNOWLEDGE

    博客分类:
  • JMS
jms 
阅读更多

使用自动确认模式,必须要创建无事务session

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

 

  AUTO_ACKNOWLEDGE:自动确认模式,一旦接收方应用程序的消息处理回调函数返回,会话对象就会确认消息的接收。 一般接收方的做法是调用consumer.setMessageListener()注册消息处理函数。如果该函数返回,代表着一条消息被接受放成功接收, ActiveMQ服务器会认为消息接收成功。函数的返回可以是正常的返回,也可以是因为抛出异常而结束。

 

接收方代码,多次允许的时候,每次都会接收到1个消息。这是因为消息处理函数没有返回,ActiveMQ会认为消息接收失败。

 String url = "tcp://localhost:61616";
        String userName = "system";
        String password = "manager";
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(userName, password, url);
        Connection connection = connectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Destination destination = session.createQueue("test_queue");
        MessageConsumer consumer = session.createConsumer(destination);

        // 消息消费者接收消息
        consumer.setMessageListener(new MessageListener()
        {
            @Override
            public void onMessage(Message msg)
            {
                TextMessage message = (TextMessage) msg;
                try
                {
                     System.out.println("收到消息:" + message.getText());
                     while(true)
		     {
			//throw new JmsException("error return");
                     }
                }
                catch (JMSException e)
                {
                    e.printStackTrace();
                }
            }
        });

 

分享到:
评论

相关推荐

    ActiveMQ_Demo

    session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE); } catch (JMSException e) { e.printStackTrace(); } } public void getMessage(String disname){ try { Queue queue = ...

    佳能相机开发EDSDK_13.10.21_for_Windows.zip

    acknowledge us. Permission is NOT granted for the use of any IJG author's name or company name in advertising or publicity relating to this software or products derived from it. This software may ...

    KCF源码代码

    If you find it useful or use it in your research, please acknowledge my git repository and cite the original paper [1]. The code depends on OpenCV 2.4+ library and is build via cmake toolchain. ___...

    testActiveMQ.rar

    session = connection->createSession(Session::AUTO_ACKNOWLEDGE); } // Create the destination (Topic or Queue) if (useTopic) { destination = session->createTopic("TEST.FOO"); } else { ...

    FM17550E_ds_chs.pdf

    4.4.4 Acknowledge .. 52 4.4.5 7 位地址 ... 53 4.4.6 寄存器写入访问 .. 54 4.4.7 寄存器读取访问 .. 54 4.4.8 高速模式 ... 55 4.4.9 高速传输 ... 55 4.4.10 HS 模式下的数据传输格式 ... 55 4.4.11 F/S ...

    IFSF协议在Lonworks上的应用

    3.3.4 "Acknowledge" - Message .........................................................................................20 3.3.5 "Unsolicited Data" - Message...............................................

    i2c总线协议英文版

    1 PREFACE. . . . . . . . . ....1.1 Version 1.0 - 1992....1.2 Version 2.0 - 198....1.3 Version 2.1 - 1999....1.4 Purchase of Philips I2C-bus ...7.2 Acknowledge. . . . . . . . . . . . . . . . . . . . . . . 10

    JLink_Windows_V648.zip

    Enabled cross trigger interfaces to forward debug acknowledge signal to Watchdog. DLL: SPI-Flash programming for Spansion S25FL256L, fixed. DLL: STM32L031K6 secure chip did not work. Fixed. DLL: STM...

    Acknowledge软件

    里边是安装后的,包括exe文件,可以尝试使用,美国biapac公司发布的好像是,用来分析脑电心电信号没问题。

    stm32 mpu_6050程序

    * Description : Master Send Acknowledge Single * Input : None * Output : None * Return : None ****************************************************************************** */ void I2C_Ack(void) { ...

    考博词汇10000全集

    考博词汇10000汇总的Excel版 abate v.减轻,减退;废除 aberrant a....异常的;脱离常轨的 ablate v....abortion n....abrade v....acknowledge v.承认;致谢 acknowledgement n.承认,感谢;收到的通知 ......

    J2EE面试题

    b) AUTO_ACKNOWLEDGE方式能确认之前收到的所有消息 c) Client_ACKNOWLEDGE方式需要显示调用方法ACKNOWLEDGE方法来显式的确认消息 d) Client_ACKNOWLEDGE方式可以确认所有的消息 参考答案 20) 关于消息Bean事务...

    80486 System Architecture [3rd Edition] [1995]

    Contents About This Book The MindShare Architecture Series.......................................................................................1 Organization of This Book...............................

    实现类似Office助手的小精灵

    Acknowledge 承认 LookDown 向下看 Sad 悲伤 Alert 警告 LookDownBlink 向下看眨眼 Search 寻找 Announce 声明 LookUp 向上看 StartListening 开始聆听 Blink 眨眼 LookUpBlink 向下看眨眼 StopListening 停止...

    Acknowledge4.2软件安装包

    Acknowledge4.2安装包,包括AckSetup.exe直接运行安装即可。

    WinGrub汉化版

    Users should acknowledge that no liability claims could be made in connection with installing and using this package, in particular the WINGRUB utility. Homepage: ...

    cc2420无线传感芯片说明手册

    19 Acknowledge Frames _______________________________________________________42 20 Radio control state machine __________________________________________________44 21 MAC Security Operations ...

    I2C总线标准(英文版)

    7.2 Acknowledge. . . . . . . . . . . . . . . . . . . . . . . 10 8 ARBITRATION AND CLOCK GENERATION . . . . . . . . . . . . . . . . . . . . . .11 8.1 Synchronization . . . . . . . . . . . . . . . . . ....

    Fundamental_Factor_Models_Using_Machine_Learning.pdf

    They acknowledge the major contributions Fama and French have made to the literature in the past and so studied this new research with great interest. However the debate is set to continue – they ...

    在JBOSS 环境中配置JMS,在程序中可以通过JNDI 获取连接

    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/queue/adaption_...

Global site tag (gtag.js) - Google Analytics