Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nebulas RPC subscribe interface issue #61

Closed
qywang2012 opened this issue Feb 11, 2018 · 6 comments
Closed

Nebulas RPC subscribe interface issue #61

qywang2012 opened this issue Feb 11, 2018 · 6 comments
Assignees

Comments

@qywang2012
Copy link
Collaborator

Nebulas subscribe interface using the long connection, RPC using gRPC connection, the long connection by a stream can work well. However, in the HTTP request, using the keep-alive can request but don't return data.

gRPC usage

	addr := fmt.Sprintf("127.0.0.1:%d", uint32(8684))
	conn, err := rpc.Dial(addr)
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	ac := rpcpb.NewApiServiceClient(conn)

	stream, err := ac.Subscribe(context.Background(), &rpcpb.SubscribeRequest{})

	if err != nil {
		log.Fatalf("could not subscribe: %v", err)
	}
	for {
		reply, err := stream.Recv()
		if err == io.EOF {
			break
		}
		if err != nil {
			log.Printf("failed to recv: %v", err)
		}
		log.Println("recv notification: ", reply.Topic, reply.Data)
	}

http usage

curl and the JS implementation of the RPC don't seem to return the data properly because the data is encoded in chunks.

const http = require("http")

callback = function(response) {
  response.on("data", function(chunk) {
    console.log(chunk.toString("utf8"))
  })
}

var req = http.request(
  {
    host: "localhost",
    port: 8685,
    path: "/v1/user/subscribe",
    method: "POST",
    headers: { "Content-Type": "application/json" },
  },
  callback
)
req.on("error", function(e) {
  console.log("problem with request: " + e.message)
})
req.write('{"topics":["chain.executeTxSuccess"]}')
req.end()

Anybody has a better way to handle the Subscribe via http?

issue

The event emitter is a non-blocking design, evnent data will be lost when the channle is full when there are many subscribed events. Since the RPC stream is sent serially, the message is not delivered in time. We need a non-blocking pipeline for event collection. Can anyone alse take this job, using kafka, redis, etc as the adapter?

The events in event trie May not response in Subscribe, This may be a bug in event emitter.

@qywang2012 qywang2012 self-assigned this Feb 11, 2018
@fbzhong
Copy link
Contributor

fbzhong commented Feb 13, 2018

Hi Larry,

How's this issue? Any updates?

@1c7
Copy link

1c7 commented Mar 2, 2019

Any update?
Why close this issue?

@1c7
Copy link

1c7 commented Mar 2, 2019

Goal: Reliably listen to event (emit by specific Smart Contract)

For Example: NRC20 token,

Following code come from official doc

    transfer: function (to, value) {
        value = new BigNumber(value);

        var from = Blockchain.transaction.from;
        var balance = this.balances.get(from) || new BigNumber(0);

        if (balance.lt(value)) {
            throw new Error("transfer failed.");
        }

        this.balances.set(from, balance.sub(value));
        var toBalance = this.balances.get(to) || new BigNumber(0);
        this.balances.set(to, toBalance.add(value));

        this.transferEvent(true, from, to, value); // <--------------How do I listen to this?
    },

Example: user transfer NAS to a Nebulas wallet address that we provide(n1...something)

We need to know that when that happen.
and give user our NRC20 token.

it's like a webhook.
I don't want to long polling. like in Web development just keep sending Ajax

@1c7
Copy link

1c7 commented Mar 2, 2019

Do I have to run a local node myself? and do this?

image

@1c7
Copy link

1c7 commented Mar 2, 2019

@1c7
Copy link

1c7 commented Mar 2, 2019

Seem like I can't subscribe to specific one Smart Contract?
subscribe seem like return all event?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants