使用activeMQ进行android推送时需要如下问题
(1)activeMQ后台报错:Frame size of 257 MB larger than max allowed 100 MB
详细错误信息:
WARN | Transport Connection to: tcp://127.0.0.1:50916 failed: java.io.IOException: Frame size of 257 MB larger than max allowed 100 MB | org.apache.activemq.broker.TransportConnection.Transport | ActiveMQ Transport: tcp:///127.0.0.1:50916@61616
解决方法:
修改配置文件apache-activemq-5.9.0-bin\apache-activemq-5.9.0\conf\activemq.xml
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=1048576000"/>
把maxFrameSize 调大一些.
(2)mqtt 客户端如何设置用户名和密码
/*** * 客户端和activeMQ服务器建立连接 * @param BROKER_URL * @param clientId : 用于标识客户端,相当于ios中的device token * @param TOPIC * @param isCleanSession :false--可以接受离线消息; * @return 是否启动成功 */ private boolean connect(String BROKER_URL,String clientId,String TOPIC,boolean isCleanSession){ try { ComponentUtil.appendResult(resultTextPane, "connect time:"+TimeHWUtil.getCurrentMiniuteSecond(), true); mqttClient = new MqttClient(BROKER_URL, clientId, new MemoryPersistence()); MqttConnectOptions options= new MqttConnectOptions(); options.setCleanSession(isCleanSession);//mqtt receive offline message ComponentUtil.appendResult(resultTextPane, "isCleanSession:"+isCleanSession, true); options.setKeepAliveInterval(30); String username=usernameTextField.getText(); String password=passwordTextField.getText(); if(ValueWidget.isNullOrEmpty(username)){ username=null; } if(ValueWidget.isNullOrEmpty(password)){ password=null; }else{ options.setPassword(password.toCharArray()); } options.setUserName(username); //推送回调类,在此类中处理消息,用于消息监听 mqttClient.setCallback(new MyCallBack(MqttClientSwing.this)); boolean isSuccess=false; try { mqttClient.connect(options);//CLIENT ID CAN NOT BE SAME isSuccess=true; } catch (Exception e) { if(isPrintException){ e.printStackTrace(); } } if(!isSuccess){ String message="连接失败,请检查client id是否重复了 或者activeMQ是否启动"; ComponentUtil.appendResult(resultTextPane, message, true); GUIUtil23.warningDialog(message); return false; }else{ //Subscribe to topics mqttClient.subscribe(new String[]{TOPIC,clientId}); System.out.println("topic:"+TOPIC+", "+(clientId)); ComponentUtil.appendResult(resultTextPane, "TOPIC:"+TOPIC+", "+(clientId), true); } } catch (MqttException e) { if(isPrintException){ e.printStackTrace();} GUIUtil23.errorDialog(e.getMessage()); return false; } return true; }
(3)发布者如何设置密码
/** * 初始化connection和session * * @throws Exception */ private void init(/* String mqIp,boolean transacted */) throws Exception { if (!DialogUtil.verifyTFEmpty(serverIpTextField, "服务器ip")) { return; } String transactedStr = transactedTextField.getText(); boolean transacted = false; if (ValueWidget.isNullOrEmpty(transactedStr)) { transacted = false; } else { transacted = Boolean.parseBoolean(transactedStr); } String message = "transacted:" + transacted; ComponentUtil.appendResult(resultTextArea, message, false); // System.out.println(message); String brokerUrl = String.format(BROKER_URL, serverIpTextField.getText()); String username=usernameTextField.getText(); String password=passwordTextField.getText(); if(ValueWidget.isNullOrEmpty(username)){ username=null; } if(ValueWidget.isNullOrEmpty(password)){ password=null; } // 创建链接工厂 TopicConnectionFactory factory = new ActiveMQConnectionFactory( username, password, brokerUrl); ComponentUtil.appendResult(resultTextArea, "activeMQ url:" + brokerUrl, true); // 通过工厂创建一个连接 connection = factory.createTopicConnection(); // 启动连接 connection.start(); ComponentUtil.appendResult(resultTextArea, "启动connection 成功", true); // 创建一个session会话 transacted session = connection.createTopicSession( transacted /* Boolean.FALSE */, Session.AUTO_ACKNOWLEDGE); }
相关推荐
NULL 博文链接:https://hw1287789687.iteye.com/blog/2067736
activeMQ推送服务端和客户端完整案例
继上篇的MQTT学习,此篇主要是实现一个安卓客户端,利用activemq服务器,实现安卓客户端之间的推送 首先需要说明客户端的结构 客户端的组成如下:
ActiveMQ MQTT Android客户端Demo
SpringBoot+ActiveMq+MQTT实现消息的发送和接收 后台消费者、生产者、消息发送接口、发送消息业务类等相关配置
ActiveMQ MQTT Android 客户端Demo
java中使用消息中间件ActiveMQ的MQTT协议发布消息使用fusesource,fusesource提供三种方式实现发布消息的方式,分别是阻塞式(BlockingConnection)、回调式(CallbackConnection)和Future样式(FutureConnection)
使用SpringMVC、Spring、ActiveMQ发送和接受Mqtt消息。
Activemq-MQTT-Websocket库Js文件mqttws31.js 前端使用Websocket连接Activemq中间件的Js库文件
mqtt前端连接客户端demo--MQTT(消息队列遥测传输)是ISO 标准(ISO/IEC PRF 20922)下基于发布/订阅范式的消息协议。它工作在 TCP/IP协议族上,是为硬件性能低下的远程设备以及网络状况糟糕的情况下而设计的发布/订阅型...
activeMq 实现mqtt 协议的 client ,mqtt-spy. 用于测试
此附件是Apache下面的一个ActiveMq客户端,如果需要在本地调试,不链接远程服务器的MQ可以下载研究。
activemq消息测试工具
mqtt协议时IBM开发的一个协议,facebook的android客户端message即时...这段代码可以实现android的消息推送。还可以在此基础实现即时通讯,在运行这段代码,还需要安装activeMQ服务器。下载地址http://activemq.apache.org/
基于activemq实现Android推送(服务端+客户端)
activemq向android推送消息实例,测试环境activemq5.9.1版,别忘了修改你的主机地址
网上其实有的 用的swing界面 演示mqtt 推送和接收消息的全过程
activemq linux下的多线程客户端,在windows下同样适用,包含生产消息客户端,和消费者消息客户端,以及生产者消息多线程客户端
通过tomcat服务器,向网页发送即时消息。comet的小例子,可以直接运行,用tomcat6.0。