根据文档https://console.ng.bluemix.net/docs/services/MessageHub/index.html#messagehub,应该可以通过REST向MessageHub提交消息,并通过MQLight客户机接收消息。然而,该文件是缺乏一个例子,是有点。。。不透明。你知道吗
因此,如果我创建MQLight主题,并让python客户机监听
import json
import logging
import mqlight
import time
amqps = 'amqps://xxxxxxxxxxxxx.messagehub.services.us-south.bluemix.net:5671'
options = {
'user' : 'xxxxxxxxxxxxxxxx',
'password' : 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}
def on_message(message_type, data, delivery):
d = json.loads(data)
print str(d)
def on_started(err):
client.subscribe('test', on_message = on_message)
def on_stopped(err):
logging.info('stopped')
client = mqlight.Client(amqps, security_options = options, client_id = 'client', on_started=on_started)
while True:
logging.info(str(client.get_state()))
time.sleep(5)
如何通过curl发布消息。我试过了,值字符串是base64编码的
curl -i \
-X POST \
-H "X-Auth-Token:${APIKEY}" \
-H "Content-Type: application/vnd.kafka.binary.v1+json" \
--data '{"records":[{"value":"S2Fma2E="}]}' \
"https://kafka-rest-prod01.messagehub.services.us-south.bluemix.net:443/topics/MQLight/test"
但这又回来了
{"error_code":404,"message":"HTTP 404 Not Found"}
你说得对,这里的文档不是特别充实。关于这一点的唯一细节在here小节中,该小节试图解释为了与来自其他Kafka或REST客户机的MQLight客户机进行交互操作,您需要能够对amqp1.0消息格式进行编码/解码(请参见spec的第3节)。你知道吗
在curl脚本中很难实现这一点,因为您需要访问amqp1.0库,即使是Python也不理想,因为当前您唯一的实际选择是拉入python-qpid-proton,因为它包装了proton-c本机库,因此需要安装时编译。你知道吗
例如,在Java中,您可以使用正式Java kafka-clients和qpid proton-j的组合来提供AMQP消息编码+解码。或者,如果您必须使用restapi,那么引入类似feign的内容。你知道吗
相关问题 更多 >
编程相关推荐