<p>Try to subscribe by using prefix <strong>raw</strong> as topic . After this you will get both message on the one listener.</p>

<pre><code>socket.subscribe('raw');

socket.on('message', (topicRaw: Buffer, bodyRaw: Buffer, ...tailRaw: Buffer[]) =&gt; {

    const sequenceRaw = tailRaw[tailRaw.length - 1];
    const sequence = sequenceRaw.readInt32LE(0);
    const topic = topicRaw.toString();


    if (topic == 'rawtx') {
        const rawTX = bodyRaw.toString('hex');
        console.log(topic, sequence, rawTX);

    } else if (topic == 'rawblock') {

        const rawBlock = bodyRaw.toString('hex', 0, 80);
        console.log(topic, sequence, rawBlock);
    }
});
</code></pre>

CC BY-SA 4.0
2018-05-05T19:05:55.100Z
2018-05-05T19:05:55.100Z
Pavel Tsarenko
<p>I need your opinion, do you mind ? :)</p>

<p>I'm bulding a javascript layer on top of bitcoind.
I have bitcoind running on my server with rpc &amp; zmq enabled.</p>

<pre><code>daemon=1
rpcallowip=0.0.0.0/0
rpcuser=xxxxxxxx
rpcpassword=xxxxxxxxx
server=1
rest=1
zmqpubhashblock=tcp://*:28332
zmqpubhashtx=tcp://*:28332
zmqpubrawblock=tcp://*:28332
zmqpubrawtx=tcp://*:28332
rpcworkqueue=100
</code></pre>

<p>My program goal is to listen for <code>rawblock</code> and <code>rawtx</code> ZMQ channels. This is my zmq client:</p>

<pre><code>const socket = ZMQ.socket('sub')
socket.connect('tcp://myserverip:28332')

socket.on('message', (channel, data) =&gt; { 
  console.log(channel.toString())
})
</code></pre>

<h3>So here is what happens :</h3>

<p>subscribing to <code>rawtx</code> <strong>alone</strong> works, I receive the tx flow (approx 2.5tx per second)</p>

<pre><code>socket.subscribe('rawtx')
</code></pre>

<p>subscribing to <code>rawblock</code> <strong>alone</strong> also works, I receive blocks (approx 1block per 10minutes)</p>

<pre><code>socket.subscribe('rawblock')
</code></pre>

<p>But here is my problem, when subscribing to <strong>both</strong>, i do receive <code>rawtx</code> but no <code>rawblock</code> !</p>

<pre><code>socket.subscribe('rawblock')
socket.subscribe('rawtx')
</code></pre>

<p>I'm assuming the ZMQ socket is flooded with <code>rawtx</code>, which result in missing <code>rawblock</code> event.</p>

<p>My question is: how would you debug this ? Have you guys faced this situation already ?</p>

<p>I know I could use the <code>blocknotify</code> option in bitcoind to forward the <code>blockhash</code> back to my client, and then load the rawblock via an <code>rpc</code> call back to bitcoind, but then I would use 2 different mechanisms (one for <code>rawtx</code> and blocknotify for <code>rawblock</code>) for something that was supposed to work in the first place :)</p>

<p>Thanks for your feedback !!</p>

CC BY-SA 3.0
2017-11-25T17:08:14.340Z
Are you sure that `socket.subscribe` allows you to subscript to multiple things in the way that you have done it? It seems like it could only be subscribing to the latest thing that `subscribe` was called on, and that would be `rawtx`. What happens if you reverse the order?
Ava Chow
CC BY-SA 3.0
2017-11-25T21:55:50.757Z
order does not matter I've checked. and if I sub to `rawtx` & `hashtx` i receive both. I just don't receive `rawblock` when used with `rawtx` at the same time
Louis Grellet
<zeromq>
rawtx & rawblock ZMQ at the same time?
Louis Grellet
# rawtx & rawblock ZMQ at the same time?

(Asked by: username_0 on 2017-11-25)

I need your opinion, do you mind ? :)

I'm bulding a javascript layer on top of bitcoind.
I have bitcoind running on my server with rpc & zmq enabled.

```
daemon=1
rpcallowip=0.0.0.0/0
rpcuser=xxxxxxxx
rpcpassword=xxxxxxxxx
server=1
rest=1
zmqpubhashblock=tcp://*:28332
zmqpubhashtx=tcp://*:28332
zmqpubrawblock=tcp://*:28332
zmqpubrawtx=tcp://*:28332
rpcworkqueue=100

```

My program goal is to listen for `rawblock` and `rawtx` ZMQ channels. This is my zmq client:

```
const socket = ZMQ.socket('sub')
socket.connect('tcp://myserverip:28332')

socket.on('message', (channel, data) => { 
  console.log(channel.toString())
})

```

### So here is what happens :

subscribing to `rawtx` **alone** works, I receive the tx flow (approx 2.5tx per second)

```
socket.subscribe('rawtx')

```

subscribing to `rawblock` **alone** also works, I receive blocks (approx 1block per 10minutes)

```
socket.subscribe('rawblock')

```

But here is my problem, when subscribing to **both**, i do receive `rawtx` but no `rawblock` !

```
socket.subscribe('rawblock')
socket.subscribe('rawtx')

```

I'm assuming the ZMQ socket is flooded with `rawtx`, which result in missing `rawblock` event.

My question is: how would you debug this ? Have you guys faced this situation already ?

I know I could use the `blocknotify` option in bitcoind to forward the `blockhash` back to my client, and then load the rawblock via an `rpc` call back to bitcoind, but then I would use 2 different mechanisms (one for `rawtx` and blocknotify for `rawblock`) for something that was supposed to work in the first place :)

Thanks for your feedback !!

**Tags:** zeromq

> **Comments:**
> **username_1**: Are you sure that `socket.subscribe` allows you to subscript to multiple things in the way that you have done it? It seems like it could only be subscribing to the latest thing that `subscribe` was called on, and that would be `rawtx`. What happens if you reverse the order?  
> **username_0**: order does not matter I've checked. and if I sub to `rawtx` & `hashtx` i receive both. I just don't receive `rawblock` when used with `rawtx` at the same time  

---

## 1 answers

### Answer by username_2 on 2018-05-05. Score: 1

Try to subscribe by using prefix **raw** as topic . After this you will get both message on the one listener.

```
socket.subscribe('raw');

socket.on('message', (topicRaw: Buffer, bodyRaw: Buffer, ...tailRaw: Buffer[]) => {

    const sequenceRaw = tailRaw[tailRaw.length - 1];
    const sequence = sequenceRaw.readInt32LE(0);
    const topic = topicRaw.toString();

    if (topic == 'rawtx') {
        const rawTX = bodyRaw.toString('hex');
        console.log(topic, sequence, rawTX);

    } else if (topic == 'rawblock') {

        const rawBlock = bodyRaw.toString('hex', 0, 80);
        console.log(topic, sequence, rawBlock);
    }
});

```


---

