1

Qpid-proton python サンプル スクリプト (send.py) を使用して、Azure Event Hub にデータを送信しています。それを確認するために、Service Bus Explorer 2.6.1.0 を使用します。Python スクリプトを使用して送信されたデータは、送信したものではなく、Service Bus Explorer で 16 進数値として表示されます。しかし、Qpid の recv.py を使用して同じものを受け取ると、期待どおりの結果が得られます。それで、これは問題ですか?

#!/usr/bin/python
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
from __future__ import print_function
import sys, optparse
from proton import *

parser = optparse.OptionParser(usage="usage: %prog [options] <msg_1> ... <msg_n>",
                               description="simple message sender")
parser.add_option("-a", "--address", default="amqp://0.0.0.0",
                  help="address: //<domain>[/<name>] (default %default)")

opts, args = parser.parse_args()
if not args:
  args = ["Hello World!"]

mng = Messenger()
mng.start()

msg = Message()
for m in args:
  msg.address = opts.address
  msg.body = unicode(m)
  mng.put(msg)

mng.send()
print("sent:", ", ".join(args))

mng.stop()

送信構文: $ python send.py -a [address] "Hello world"

また、Azure python SDK を使用してデータを送信しようとしました。そのサンプル データは Service Bus Explorer で正しく受信されます。

4

1 に答える 1

0

qpid-proton python を使用してメッセージを EventHub に送信してこの問題を再現しようとしましたが、失敗しました。

その後、Azure Python SDK を使用してメッセージを送信し、Service Bus Explorer でメッセージを受信しましたが、それらのイベント データは Hex 形式で表示されませんでした。この問題は、qpid-proton python を使用してイベント データを文字コーディングでシリアル化することが原因であると思われます。Unicode の代わりに「UTF-8」を使用する必要があります。Python2 では、UTF-8 文字列はu"Hello World!".

于 2015-10-01T05:29:31.417 に答える