- 浏览: 7251216 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (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 POST MQTT 发布消息服务端使用
参阅官方文档
http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/topic/com.ibm.mq.csqzau.doc/ts21220_.htm
HTTP POST puts a message to a queue, or a publication to a topic. The HTTPPOST Java sample is an example an HTTP POST request of a message to a queue. Instead of using Java, you could create an HTTP POST request using a browser form, or an AJAX toolkit instead.
Figure 1 shows an HTTP request to put a message on a queue called myQueue. This request contains the HTTP header x-msg-correlId to set the correlation ID of the WebSphere MQ message.
POST /msg/queue/myQueue/ HTTP/1.1 Host: www.example.org Content-Type: text/plain x-msg-correlID: 1234567890 Content-Length: 50 Here's my message body that will appear on the queue.
Figure 2 shows the response sent back to the client. There is no response content.
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: 0
请求的协议格式和请求的响应格式
The HTTP POST operation puts a message on a WebSphere® MQ queue, or publishes a message to a topic.
Syntax
Request >>-POST-- --| Path |-- --HTTP version--CRLF---------------------> .-CRLF---------------. .-CRLF---------------. V | V | >----+----------------+-+----+----------------+-+---------------> '-general-header-' '-request-header-' .-CRLF----------------------------. .-CRLF----. V | V | >----+-----------------------------+-+--CRLF----Message-+------>< '-| entity header (Request) |-' Path |--/--contextRoot--/--------------------------------------------> >--msg/--+-queue/--queueName--+-------------+-+--/--------------| | '-@--qMgrName-' | '-topic/--topicName------------------' entity-header (Request) |--+----------------------------------------------+-------------| +-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-require-headers-- --entity header name-+ '-x-msg-usr-- --user properties----------------'
- 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) |-' 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-----------'
package com.etrip.mqttv3.http; /** * This sample shows how to post a message. It has the same behaviour as the * amqsput command in that it will read in lines from the command line and put * them to the queue. It will put non-persistent String messages on to the queue * with UNLIMITED expiry and LOW (0) priority. The program is terminated by * either EOF being put into the entry line (^Z on windows) or a blank line. * usage: java HTTPPOST <Queue (default=SYSTEM.DEFAULT.LOCAL.QUEUE)> <host:port * (default localhost:8080> <context-root (the MQ Bridge for HTTP's * context-root)> */ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; /** * * 采用HTTP POST发布相关的消息 * The HTTP POST operation puts a message on a WebSphere® MQ queue, or publishes * a message to a topic. * * 发布消息到主题或者队列的路径: * * * * * * @author longgangbai */ public class HTTPPOST { 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"; private static final String CRLF = "\r\n"; public static int MALFORMED_URL_EXCEPTION_RC = -1; public static int END_IOEXCEPTION_RC = -2; /** * 构建发布主题队列路径 * * @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(); } /** * * @param host * @param port * @param context * @param queueName * @param message * @return * @throws MalformedURLException */ public static boolean publishTopic(String host,String port,String context,String queueName,String message ){ boolean response = true; HttpURLConnection connection=null; try { String publishURL=getPublishQueueURL(host, port, context, queueName); URL url=new URL(publishURL); connection = (HttpURLConnection) url.openConnection(); /* Build the headers */ // the verb first connection.setRequestMethod("POST"); // Content type is a string message connection.setRequestProperty("content-type", "text/plain"); // set the message priority to low connection.setRequestProperty("x-msg-priority", "LOW"); // Ensure we can get the output stream from the connection connection.setDoOutput(true); OutputStream outputStream = connection.getOutputStream(); // wrapper the outputstream in a writer BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( outputStream)); // Now write the actual content. // Make sure the CRLF is there in case some HTTP servers don't understand // that it's the end of the message writer.write(message + CRLF + CRLF); writer.flush(); // now actually send the message connection.connect(); // check the response for errors int responseCode = connection.getResponseCode(); if (responseCode != 200) { String responseMessage =connection.getResponseMessage(); System.out.println("responsere sponseCode "+responseCode+" response request ="+responseMessage); System.out.println("responsere context "); BufferedReader reader = new BufferedReader(new InputStreamReader( connection.getErrorStream())); String line = null; while ((line = reader.readLine()) != null) { System.out.println(line); } connection.disconnect(); response = false; }else{ //获取相应的消息头信息 String responseQueueName=connection.getHeaderField("x-msg-replyTo"); System.out.println("responseQueueName="+responseQueueName); System.out.println("response successful context :"+connection.getResponseMessage()); } } catch (MalformedURLException e) { response = false; e.printStackTrace(); // TODO: handle exception } catch (IOException e) { response = false; // TODO Auto-generated catch block e.printStackTrace(); }finally{ connection.disconnect(); } return response; } public static void main(String[] args) { HTTPPOST.publishTopic("192.168.208.46", "8080", "mq", "java_lover", "this is a message "); } }
http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/topic/com.ibm.mq.csqzau.doc/ts21220_.htm
http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/topic/com.ibm.mq.csqzau.doc/ts21250_.htm
发表评论
-
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 9380TestNG官方文档的地址: 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客户端的...
网上找的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 ...
MQTT服务端,在本地直接打开可用,可配合之前发的MQTT客户端使用。
mqtt+服务端+客户端
mqtt服务端搭建到android使用教程 详细
Winform中使用MQTTnet实现MQTT的服务端和客户端之间的通信以及将订阅的消息保存到文件示例代码.rar Winform中使用MQTTnet实现MQTT的服务端和客户端之间的通信以及将订阅的消息保存到文件示例代码.rar Winform中使用...
MQTTnet在.net core(2.2版本)开发环境下的实例代码,包含服务端,两个客户端(订阅、发布),并在阿里云的mqtt服务测试过可用
winForm中使用MQTT收发消息,不懂的可以联系qq:502701291
Android开发,通过使用mqtt3.1.1版本和mqtt5.0版本进行mqtt数据的发送和接收,实现和服务端数据的交互
此Demo对应本人博客文章《MQTT(一)C#使用 MQTTnet 快速实现 MQTT 通信》 开发环境Win7 + vs2017
MQTT服务器服务端
java中使用消息中间件ActiveMQ的MQTT协议发布消息使用fusesource,fusesource提供三种方式实现发布消息的方式,分别是阻塞式(BlockingConnection)、回调式(CallbackConnection)和Future样式(FutureConnection)
mqtt开发C语言基于paho实现MQTT客户端实战案例
使用高性能的MQTTnet搭建的server和client例程,亲测可用。MQTTnet 是一个基于 MQTT 通信的高性能 .NET 开源库,它同时支持 MQTT 服务器端和客户端。
该项目涵盖uniapp框架设计的web客户端(内置丰富的组件使用实例及http、mqtt客户端服务端通信),以及基于node.js的express框架设计的服务端(内置http、mqtt服务端架构实例),数据库使用传统数据库MySQL。...
基于paho.mqtt.c实现mqtt,具体教程见本人的博客
MQTT(MessageQueuingTelemetryTransport,消息队列遥测传输)是IBM开发的一个即时通讯协议,它是一种轻量级的、基于代理的“发布/订阅”模式的消息传输协议。其具有协议简洁、小巧、可扩展性强、省流量、省电等优点...