如何订阅 sawtooth hyperledger 中的事件?
How to subscribe to events in sawtooth hyperledger?
我正在按照 sawtooth hyperledger api doc 中给出的步骤创建增量事件订阅者。
出于某种原因,它无法正常工作,我在锯齿状日志中看到以下内容
[2019-07-18 18:14:41.003 INFO dispatch] received a message of type CLIENT_EVENTS_SUBSCRIBE_REQUEST from fc9a2db054180e53269ec4c0cad18482afe6f4307251ca7d673f8b723c3293abc5b1c2c07b827705cdf0d9a145f8f44cdf546971c05fd67244a01e4cb1ccc9c2 but have no handler for that type
[2019-07-18 18:16:46.474 INFO interconnect] No response from fc9a2db054180e53269ec4c0cad18482afe6f4307251ca7d673f8b723c3293abc5b1c2c07b827705cdf0d9a145f8f44cdf546971c05fd67244a01e4cb1ccc9c2 in 125.4719786643982 seconds - removing connection.
我也试过使用 Sawtooth Simple Supply 但我仍然看到同样的错误。有人可以告诉我我可能做错了什么吗?
锯齿波:1.1.5
Python : 3.6.8
尝试使用不同的示例。
代码:
import zmq
from sawtooth_sdk.protobuf.events_pb2 import EventSubscription, EventFilter, EventList
from sawtooth_sdk.protobuf.client_event_pb2 import ClientEventsSubscribeRequest, ClientEventsSubscribeResponse
from sawtooth_sdk.protobuf import block_pb2, events_pb2, client_event_pb2
from sawtooth_sdk.protobuf import state_context_pb2
from sawtooth_sdk.protobuf import transaction_receipt_pb2
from sawtooth_sdk.protobuf.validator_pb2 import Message
from sawtooth_sdk.processor.core import TransactionProcessor
import time
AUTH_KEY_NAMESPACE = '7f1029.*'
URL='tcp://192.168.17.185:8800'
subscription = EventSubscription(
event_type="sawtooth/state-delta",
filters=[
# Filter to only addresses in the "xo" namespace using a regex
EventFilter(
key="address",
match_string=AUTH_KEY_NAMESPACE,
filter_type=EventFilter.REGEX_ANY)
])
ctx = zmq.Context()
socket = ctx.socket(zmq.DEALER)
socket.connect(URL)
# Construct the request
request = ClientEventsSubscribeRequest(
subscriptions=[subscription]).SerializeToString()
# Construct the message wrapper
correlation_id = "123" # This must be unique for all in-process requests
msg = Message(
correlation_id=correlation_id,
message_type=Message.MessageType.CLIENT_EVENTS_SUBSCRIBE_REQUEST,
content=request)
# Send the request
socket.send_multipart([msg.SerializeToString()])
# Receive the response
resp = socket.recv_multipart()[-1]
# Parse the message wrapper
msg = Message()
msg.ParseFromString(resp)
# Validate the response type
if msg.message_type != Message.MessageType.CLIENT_EVENTS_SUBSCRIBE_RESPONSE:
print("Unexpected message type")
exit(1)
print("Got Subscribe Response")
# Parse the response
msg = Message()
msg.ParseFromString(resp)
# Validate the response type
if msg.message_type != Message.MessageType.CLIENT_EVENTS_SUBSCRIBE_RESPONSE:
print("Unexpected message type")
exit(1)
print("Got Subscribe Response")
# Parse the response
response = ClientEventsSubscribeResponse()
response.ParseFromString(msg.content)
# Validate the response status
if response.status != ClientEventsSubscribeResponse.OK:
print("Subscription failed: {}".format(response.response_message))
exit(1)
print("Subscribe response is ok")
while True:
resp = socket.recv_multipart()[-1]
# Parse the message wrapper
msg = Message()
msg.ParseFromString(resp)
# Validate the response type
if msg.message_type != CLIENT_EVENTS:
print("Unexpected message type")
exit(1)
# Parse the response
events = EventList()
events.ParseFromString(msg.content)
for event in events:
print(event)
我在 Python3 中有一个 Hyperledger Sawtooth 事件处理程序的工作示例。
我也有一个用 Go 写的。参见:
https://github.com/danintel/sawtooth-cookiejar/tree/master/events
摆脱 EventFilter,看看它是否有效。
我从来没有用过 ZMQ。我使用 Sawtooth Stream 接口发送我的请求。
我正在按照 sawtooth hyperledger api doc 中给出的步骤创建增量事件订阅者。
出于某种原因,它无法正常工作,我在锯齿状日志中看到以下内容
[2019-07-18 18:14:41.003 INFO dispatch] received a message of type CLIENT_EVENTS_SUBSCRIBE_REQUEST from fc9a2db054180e53269ec4c0cad18482afe6f4307251ca7d673f8b723c3293abc5b1c2c07b827705cdf0d9a145f8f44cdf546971c05fd67244a01e4cb1ccc9c2 but have no handler for that type [2019-07-18 18:16:46.474 INFO interconnect] No response from fc9a2db054180e53269ec4c0cad18482afe6f4307251ca7d673f8b723c3293abc5b1c2c07b827705cdf0d9a145f8f44cdf546971c05fd67244a01e4cb1ccc9c2 in 125.4719786643982 seconds - removing connection.
我也试过使用 Sawtooth Simple Supply 但我仍然看到同样的错误。有人可以告诉我我可能做错了什么吗?
锯齿波:1.1.5
Python : 3.6.8
尝试使用不同的示例。 代码:
import zmq
from sawtooth_sdk.protobuf.events_pb2 import EventSubscription, EventFilter, EventList
from sawtooth_sdk.protobuf.client_event_pb2 import ClientEventsSubscribeRequest, ClientEventsSubscribeResponse
from sawtooth_sdk.protobuf import block_pb2, events_pb2, client_event_pb2
from sawtooth_sdk.protobuf import state_context_pb2
from sawtooth_sdk.protobuf import transaction_receipt_pb2
from sawtooth_sdk.protobuf.validator_pb2 import Message
from sawtooth_sdk.processor.core import TransactionProcessor
import time
AUTH_KEY_NAMESPACE = '7f1029.*'
URL='tcp://192.168.17.185:8800'
subscription = EventSubscription(
event_type="sawtooth/state-delta",
filters=[
# Filter to only addresses in the "xo" namespace using a regex
EventFilter(
key="address",
match_string=AUTH_KEY_NAMESPACE,
filter_type=EventFilter.REGEX_ANY)
])
ctx = zmq.Context()
socket = ctx.socket(zmq.DEALER)
socket.connect(URL)
# Construct the request
request = ClientEventsSubscribeRequest(
subscriptions=[subscription]).SerializeToString()
# Construct the message wrapper
correlation_id = "123" # This must be unique for all in-process requests
msg = Message(
correlation_id=correlation_id,
message_type=Message.MessageType.CLIENT_EVENTS_SUBSCRIBE_REQUEST,
content=request)
# Send the request
socket.send_multipart([msg.SerializeToString()])
# Receive the response
resp = socket.recv_multipart()[-1]
# Parse the message wrapper
msg = Message()
msg.ParseFromString(resp)
# Validate the response type
if msg.message_type != Message.MessageType.CLIENT_EVENTS_SUBSCRIBE_RESPONSE:
print("Unexpected message type")
exit(1)
print("Got Subscribe Response")
# Parse the response
msg = Message()
msg.ParseFromString(resp)
# Validate the response type
if msg.message_type != Message.MessageType.CLIENT_EVENTS_SUBSCRIBE_RESPONSE:
print("Unexpected message type")
exit(1)
print("Got Subscribe Response")
# Parse the response
response = ClientEventsSubscribeResponse()
response.ParseFromString(msg.content)
# Validate the response status
if response.status != ClientEventsSubscribeResponse.OK:
print("Subscription failed: {}".format(response.response_message))
exit(1)
print("Subscribe response is ok")
while True:
resp = socket.recv_multipart()[-1]
# Parse the message wrapper
msg = Message()
msg.ParseFromString(resp)
# Validate the response type
if msg.message_type != CLIENT_EVENTS:
print("Unexpected message type")
exit(1)
# Parse the response
events = EventList()
events.ParseFromString(msg.content)
for event in events:
print(event)
我在 Python3 中有一个 Hyperledger Sawtooth 事件处理程序的工作示例。 我也有一个用 Go 写的。参见:
https://github.com/danintel/sawtooth-cookiejar/tree/master/events
摆脱 EventFilter,看看它是否有效。
我从来没有用过 ZMQ。我使用 Sawtooth Stream 接口发送我的请求。