- 浏览: 7251106 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (1546)
- 企业中间件 (236)
- 企业应用面临的问题 (236)
- 小布Oracle学习笔记汇总 (36)
- Spring 开发应用 (54)
- IBatis开发应用 (16)
- Oracle基础学习 (23)
- struts2.0 (41)
- JVM&ClassLoader&GC (16)
- JQuery的开发应用 (17)
- WebService的开发应用 (21)
- Java&Socket (44)
- 开源组件的应用 (254)
- 常用Javascript的开发应用 (28)
- J2EE开发技术指南 (163)
- EJB3开发应用 (11)
- GIS&Mobile&MAP (36)
- SWT-GEF-RCP (52)
- 算法&数据结构 (6)
- Apache开源组件研究 (62)
- Hibernate 学习应用 (57)
- java并发编程 (59)
- MySQL&Mongodb&MS/SQL (15)
- Oracle数据库实验室 (55)
- 搜索引擎的开发应用 (34)
- 软件工程师笔试经典 (14)
- 其他杂项 (10)
- AndroidPn& MQTT&C2DM&推技术 (29)
- ActiveMQ学习和研究 (38)
- Google技术应用开发和API分析 (11)
- flex的学习总结 (59)
- 项目中一点总结 (20)
- java疑惑 java面向对象编程 (28)
- Android 开发学习 (133)
- linux和UNIX的总结 (37)
- Titanium学习总结 (20)
- JQueryMobile学习总结 (34)
- Phonegap学习总结 (32)
- HTML5学习总结 (41)
- JeeCMS研究和理解分析 (9)
最新评论
-
lgh1992314:
[u][i][b][flash=200,200][url][i ...
看看mybatis 源代码 -
尼古拉斯.fwp:
图片根本就不出来好吧。。。。。。
Android文件图片上传的详细讲解(一)HTTP multipart/form-data 上传报文格式实现手机端上传 -
ln94223:
第一个应该用排它网关吧 怎么是并行网关, 并行网关是所有exe ...
工作流Activiti的学习总结(八)Activiti自动执行的应用 -
ZY199266:
获取不到任何消息信息,请问这是什么原因呢?
ActiveMQ 通过JMX监控Connection,Queue,Topic的信息 -
xiaoyao霄:
DestinationSourceMonitor 报错 应该导 ...
ActiveMQ 通过JMX监控Connection,Queue,Topic的信息
MQTT的学习研究(八)基于HTTP DELETE MQTT 订阅消息服务端使用
参看官方文档
HTTP DELETE 订阅主题请求协议和响应协议
http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/topic/com.ibm.mq.csqzau.doc/ts21240_.htm
请求响应头各个字段的含义的讲解
http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/topic/com.ibm.mq.csqzau.doc/ts21250_.htm
响应错误处理
http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/topic/com.ibm.mq.csqzau.doc/ts21340_.htm
The HTTP DELETE operation gets a message from a WebSphere® MQ queue, or retrieves a publication from a topic. The message is removed from the queue. If the publication is retained, it is not removed. A response message is sent back to the client including information about the message.
Syntax
Request >>-+-DELETE-+-- --| Path |-- --HTTP version--CRLF---------------> '-GET----' .-CRLF---------------. .-CRLF---------------. V | V | >----+----------------+-+----+----------------+-+---------------> '-general-header-' '-request-header-' .-CRLF----------------------------. V | >----+-----------------------------+-+------------------------->< '-| Entity-header (Request) |-' Path |--/--contextRoot--/--------------------------------------------> >--msg/--+-queue/--queueName--+-------------+-+--/--------------| | '-@--qMgrName-' | '-topic/--topicName------------------' entity-header (Request) |--+----------------------------------------------+-------------| +-standard entity-header-- --entity-value------+ +-x-msg-correlId - --correlation ID------------+ +-x-msg-msgId - --message ID-------------------+ +-x-msg-range-- --range------------------------+ +-x-msg-require-headers-- --entity header name-+ '-x-msg-wait - --wait time---------------------'
- If a question mark (?) is used it must be substituted with %3f. For example, orange?topic should be specified as orange%3ftopic.
- @qMgrName is only valid on an HTTP POST
Response >>-HTTP version-- --HTTP Status-Code-- --HTTP Reason-Phrase--CRLF--> .-CRLF---------------. .-CRLF----------------. V | V | >----+----------------+-+----+-----------------+-+--------------> '-general-header-' '-response-header-' .-CRLF-----------------------------. V | >----+------------------------------+-+--+---------------+----->< '-| Entity-header (Response) |-' '-CRLF--Message-' entity-header (Response) |--+-----------------------------------------+------------------| +-standard entity-header-- --entity-value-+ +-x-msg-class-- --message type------------+ +-x-msg-correlId-- --correlation ID-------+ +-x-msg-encoding-- --encoding type--------+ +-x-msg-expiry-- --duration---------------+ +-x-msg-format-- --message format---------+ +-x-msg-msgId-- --message ID--------------+ +-x-msg-persistence-- --persistence-------+ +-x-msg-priority-- --priority class-------+ +-x-msg-replyTo-- --reply-to queue--------+ +-x-msg-timestamp-- --HTTP-date-----------+ '-x-msg-usr-- --user properties-----------'
Request parameters
Response parameters
Description
If the HTTP DELETE request is successful, the response message contains the data retrieved from the WebSphere MQ queue. The number of bytes in the body of the message is returned in the HTTP Content-Length header. The status code for the HTTP response is set to 200 OK. If x-msg-range is specified as 0, or 0-0, then the status code of the HTTP response is 204 No Content.
If the HTTP DELETE request is unsuccessful, the response includes a WebSphere MQ bridge for HTTP error message and an HTTP status code.
HTTP DELETE example
HTTP DELETE gets a message from a queue and deletes the message, or retrieves and deletes a publication. The HTTPDELETE Java sample is an example an HTTP DELETE request reading a message from a queue. Instead of using Java, you could create an HTTP DELETE request using a browser form, or an AJAX toolkit instead.
Figure 1 is an HTTP request to delete the next message on queue called myQueue. In response, the message body is returned to the client. In WebSphere MQ terms, HTTP DELETE is a destructive get.
The request contains the HTTP request header x-msg-wait, which instructs WebSphere MQ bridge for HTTP how long to wait for a message to arrive on the queue. The request also contains the x-msg-require-headers request header, which specifies that the client is to receive the message correlation ID in the response.
DELETE /msg/queue/myQueue/ HTTP/1.1 Host: www.example.org x-msg-wait: 10 x-msg-require-headers: correlID
Figure 2, is the response returned to the client. The correlation ID is returned to the client, as requested in x-msg-require-headers of the request.
HTTP/1.1 200 OK Date: Wed, 2 Jan 2007 22:38:34 GMT Server: Apache-Coyote/1.1 WMQ-HTTP/1.1 JEE-Bridge/1.1 Content-Length: 50 Content-Type: text/plain; charset=utf-8 x-msg-correlId: 1234567890 Here's my message body that will appear on the queue.
HTTP DELETE订阅主题信息
package com.etrip.mqttv3.http; /** * This sample shows how to delete a message. It has slightly enhanced function * of the amqsget command in that it will print out the timestamp, expiry and * persistence of the messages. The program continues until the queue is empty * or a request fails. This program can potentially take in three parameters: * <queueName> * <host:port> <context-root (the MQ Bridge for HTTP's context-root)> * defaults are: SYSTEM.DEFAULT.LOCAL.QUEUE localhost:8080 mq * * If there are any exceptions thrown from this program or errors returned from the server then they are * printed to standard output as-is. * * No more messages * HTTP DELETE Sample end */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; /** * * 采用HTTP DELETE方式的订阅相关的MQTT的主题的信息 * * @author longgangbai * * */ public class HTTPDELETE { private static final String DEFAULT_HOST = "localhost"; private static final String DEFAULT_PORT = "8080"; private static final String DEFAULT_QUEUE = "SYSTEM.DEFAULT.LOCAL.QUEUE"; private static final String DEFAULT_CONTEXT_ROOT = "mq"; public static String newline = System.getProperty("line.separator"); private static final String MESSAGE_BOUNDARY = "_________________________________________________________________________________________"; // the maximum length of the message that we want to print to the screen private static final int MAX_OUTPUT_MESSAGE_SIZE = 256; private static int OK_RC = 200; /** * 构建订阅主题队列路径 * * @param host * @param port * @param context * @param queueName */ private static String getPublishQueueURL(String host, String port, String context, String queueName) { StringBuffer urlString =new StringBuffer("http://"); if(StringUtils.isEmtry(host)){ host=DEFAULT_HOST; } if(StringUtils.isEmtry(port)){ port=DEFAULT_PORT; } urlString.append(host).append(":").append(port); if(StringUtils.isEmtry(context)){ context=DEFAULT_CONTEXT_ROOT; } urlString.append("/"); urlString.append(context); urlString.append("/msg/queue/"); if(StringUtils.isEmtry(queueName)){ queueName=DEFAULT_QUEUE; } urlString.append(queueName); System.out.println("urlString="+urlString); return urlString.toString(); } /** * 通过HTTP POST 订阅主题的具体实现 * @param host * @param port * @param context * @param queueName * @return * @throws MalformedURLException */ public static boolean subTopic(String host,String port,String context,String queueName ){ String publishURL=getPublishQueueURL(host, port, context, queueName); URL url=null; HttpURLConnection connection=null; try { url = new URL(publishURL); connection= (HttpURLConnection) url.openConnection(); /* Build the headers */ // the verb first. connection.setRequestMethod("DELETE"); // write out what headers we want back // the header names are case-sensitive connection.setRequestProperty("x-msg-require-headers", "timestamp, expiry, persistence"); // Now actually send the request message. There is no content as this is a // DELETE connection.connect(); String formattedMessage = null; // check the response for errors int responseCode = connection.getResponseCode(); if (responseCode == OK_RC) { // Get the headers first String timestamp = connection.getHeaderField("x-msg-timestamp"); String expiry = connection.getHeaderField("x-msg-expiry"); String persistence = connection.getHeaderField("x-msg-persistence"); // now get the message data BufferedReader reader = new BufferedReader(new InputStreamReader( connection.getInputStream())); String line = null; StringBuffer messageBuffer = new StringBuffer(); while ((line = reader.readLine()) != null) { messageBuffer.append(line); } String messageBody = messageBuffer.toString(); formattedMessage = MESSAGE_BOUNDARY + newline; // Which is greater the max output message size or the message length? int messageSizeToPrint = messageBody.length() > MAX_OUTPUT_MESSAGE_SIZE ? MAX_OUTPUT_MESSAGE_SIZE : messageBody.length(); formattedMessage += messageBody.substring(0, messageSizeToPrint) + newline; formattedMessage += "timestamp = " + timestamp + newline; formattedMessage += "expiry = " + expiry + newline; formattedMessage += "persistence = " + persistence + newline; System.out.println("formattedMessage "+formattedMessage); }else{ String responseMessage =connection.getResponseMessage(); System.out.println("responsere sponseCode "+responseCode+" response request ="+responseMessage); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ connection.disconnect(); } return false; } public static void main(String[] args) { HTTPDELETE.subTopic("192.168.208.46", "8080", "mq", "java_lover"); } }
发表评论
-
TestNG简单的学习(十三)TestNG中Junit的实现
2013-12-04 09:00 3287TestNG和junit的整合 ... -
TestNG简单的学习(十二)TestNG运行
2013-12-03 09:08 51445文档来自官方地址: ... -
TestNG简单的学习(十一)TestNG学习总结
2013-12-03 09:08 13994最近一直在学习关于TestNG方面的知识,根 ... -
TestNG简单的学习(十)TestNG @Listeners 的使用
2013-12-03 09:07 8624TestNG官方网站: http://testng.or ... -
TestNG简单的学习(九)TestNG Method Interceptors 的使用
2013-12-03 09:07 2654TestNG官方网站: http://testng ... -
TestNG简单的学习(八)TestNG Annotation Transformers 的使用
2013-12-03 09:07 2757TestNG官方网站: http://testng.or ... -
TestNG简单的学习(七)TestNG编程方式运行
2013-12-02 09:22 2396TestNG官方网站: http://testng.or ... -
TestNG简单的学习(六)测试工厂注释的使用
2013-12-02 09:22 2713TestNG官方网站: http://testng.or ... -
TestNG简单的学习(五)参数化测试数据的定制
2013-12-02 09:22 2641TestNG官方网站: http://testng.or ... -
TestNG简单的学习(四)测试方法通过名称名称依赖实现
2013-12-02 09:21 2032TestNG官方网站: http://testng.or ... -
TestNG简单的学习(三)测试方法通过测试分组依赖实现
2013-12-02 09:21 2765TestNG官方网站: http://testng.or ... -
TestNG简单的学习(二)参数化测试并发且多方法测试方法判定
2013-11-29 15:35 3635TestNG官方网站: http://testng.or ... -
TestNG简单的学习(一)类和方法级别@Test的区别
2013-11-29 15:31 9379TestNG官方文档的地址: http://testng ... -
Feed4Junit的简单使用(七)Feed4TestNg
2013-11-29 13:35 6081在Feed4Junit主要针对junit实现的 ... -
Feed4Junit的简单使用(六)数据来特定格式文件
2013-11-29 12:29 2687Feed4Junit官方地址: http://da ... -
Feed4Junit的简单使用(五)数据来自动态约束数据
2013-11-29 12:29 2562Feed4Junit官方地址: http://datab ... -
Feed4Junit的简单使用(四)数据来自定义数据源
2013-11-28 14:09 3039Feed4Junit官方地址: http://databe ... -
Feed4Junit的简单使用(三)数据源来自数据库
2013-11-28 13:58 3097Feed4Junit官方地址: http://databe ... -
Feed4Junit的简单使用(二)数据源来自文件
2013-11-28 13:50 4521Feed4Junit官方地址: http://datab ... -
Feed4Junit的简单使用(一)
2013-11-28 13:47 2158Feed4Junit官方地址: http://databe ...
相关推荐
C# 基于MQTTNet的服务端与客户端通信案例
官方下载的MQTTNet服务端实例用的基于MQTTNet的服务端,不支持Websocket交互,通过反复查阅资料,使用基于.Net Core(3.1) 和MQTTnet.AspNetCore(3.0.9)的服务端程序可以实现同时支持cs客户端、Websocket客户端的...
Winform中使用MQTTnet实现MQTT的服务端和客户端之间的通信以及将订阅的消息保存到文件示例代码.rar Winform中使用MQTTnet实现MQTT的服务端和客户端之间的通信以及将订阅的消息保存到文件示例代码.rar Winform中使用...
网上找的MQTT服务端的实现,代码有基本注释,自己研究一下
MQTT协议的PHP服务端demo
基于 t-io 实现的低延迟、高性能的 mqtt 物联网组件 支持 MQTT v3.1、v3.1.1 以及 v5.0 协议。 支持 websocket mqtt 子协议(支持 mqtt.js)。 支持 http rest api,http api 文档详见。 支持 MQTT client ...
springboot+idea+java+mqtt实现订阅者订阅消息 针对业务需要和硬件对接,使用mqtt来处理硬件的数据 java实现订阅者订阅消息,以及处理硬件的数据 是根据业务场景写的demo,包括数据库什么的就不再上传,大家可以根据...
MQTT服务端,在本地直接打开可用,可配合之前发的MQTT客户端使用。
mqtt+服务端+客户端
mqtt服务端搭建到android使用教程 详细
winForm中使用MQTT收发消息,不懂的可以联系qq:502701291
MQTTnet在.net core(2.2版本)开发环境下的实例代码,包含服务端,两个客户端(订阅、发布),并在阿里云的mqtt服务测试过可用
针对MQTT 协议在物联网系统发布/订阅方法中会造成很多无用消息的推送,增加服务器的负载和通信带宽的问题,结合基于内容的发布订阅中根据事件内容来指定订阅条件的思想,将基于内容进行发布的消息给予特定的主题,将...
MQTT发布/订阅消息机制
mqtt实现demo
mqtt开发C语言基于paho实现MQTT客户端实战案例
SpringBoot整合MQTT服务器实现消息的发送与订阅(推送消息与接收推送)客户端类与回调方法.rar 博客地址:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/112394731
目录 一、简介 ...MQTT 全称为 Message Queuing Telemetry Transport(消息队列遥测传输)是一种基于发布/订阅范式的“轻量级”消息协议,由 IBM 发布。 MQTT 可以被解释为一种低开销,低带宽占用
此Demo对应本人博客文章《MQTT(一)C#使用 MQTTnet 快速实现 MQTT 通信》 开发环境Win7 + vs2017
Android开发,通过使用mqtt3.1.1版本和mqtt5.0版本进行mqtt数据的发送和接收,实现和服务端数据的交互