stomp-js / stompjs

Javascript and Typescript Stomp client for Web browsers and node.js apps
Apache License 2.0
773 stars 82 forks source link

BinaryBody & ActiveMq #22

Closed azriel46d closed 4 years ago

azriel46d commented 6 years ago

Hi, first of all great work on the library.

I am having trouble with using the library with ActiveMQ for Binary Bodies

if (data) {
    binaryData = new TextEncoder().encode(JSON.stringify(data))
}

client.publish({
    destination: '/topic/' + topic,
    binaryBody: binaryData,
    headers: {
        'content-type': 'application/octet-stream'
    }
})

I see in Chrome dev tools as the binary frame being sent however nothing is received on activeMQ. I am suspecting that it is activeMQ configuration however all I can find is this:

Stomp is a very simple protocol - that's part of the beauty of it! As such, it does not have knowledge of JMS messages such as TextMessage's or BytesMessage's. The protocol does however support a content-length header. To provide more robust interaction between STOMP and JMS clients, ActiveMQ keys off of the inclusion of this header to determine what message type to create when sending from Stomp to JMS. 

I tried adding explicitly the content-length but still to no avail. Is there something which I'm missing out?

kum-deepak commented 6 years ago

I have not tested binary messages with ActiveMQ. I will setup a broker and test in the coming week.

kum-deepak commented 5 years ago

I tried couple of different ways, so far no success. If you figure out something please let me know.

azriel46d commented 5 years ago

So far anything I have tried has failed as well. I will probably attempt with a different library first to see if somehow it is an issue there as well.

kum-deepak commented 5 years ago

As per their documentation if AnctiveMQ finds a content-length header it treats the payload as binary (https://activemq.apache.org/stomp.html#Stomp-WorkingwithJMSText/BytesMessagesandStomp). This library by default adds content-length header.

If you test with other library or combination it will be really helpful.

kum-deepak commented 5 years ago

If you are already using ActiveMQ it may be helpful if you can send a binary message from outside WebStomp and check if this library is able to receive it.

parmy commented 5 years ago

Moved to #113

Hi

Thanks for providing a great library, even though I haven't quite got it to work yet.

I'm hoping to connect to a ActiveMQ server, which will send GZIP messages.

I tried:

https://github.com/easternbloc/node-stomp-client Following an article I read here: https://medium.com/@mackplevine/using-activemq-with-node-js-stomp-and-http-b251ce8d995

I manage to connect to the client using the package, with the following:


    var options = {
        address:            'some url',
        port:       '61613',
        user:       'username',
        pass:       'password',
        protocolVersion: '1.0' <-- could also be '1.1'
    }

var stompClient = new require('stomp-client')(options);

stompClient.connect(function(sessionId) {
        stompClient.subscribe('/topic/...', function(body, headers) {
        }
})

I manage to make a connection and it's stable. However, without a major overhaul the stomp-client project cannot process message bodies which are sent compressed (gzip).

I came across your library, which appears to handle binary messages. However, I'm unable to connect to the ActiveMQ server.

Here's my attempt:

    var options = {
        address:            'some url',
        port:       '61613',
        user:       'username',
        pass:       'password',
        protocolVersion: '1.0' <-- could also be '1.1'
    }
    const stompConfig = {
      connectHeaders: {
        login:      options["address"],
        passcode:   options["pass"]
      },

      brokerURL: "ws://" + options["address"] + ":" + options["port"],

      debug: function (str) {
        console.log('STOMP: ' + str);
      },

      reconnectDelay: 200,

      onConnect: function (frame) {

        const subscription = stompClient.subscribe('/topic/ ... .... ', function (message) {
            console.log(message);
        });
      }
    };

    stompClient = new StompJs.Client(stompConfig);

    stompClient.activate();

I've tried various things options with address, prefixing it with "ws://" and without. stomp-client didn't require "ws://".

I'm running this in a node client and I get the following error message:

(node:4226) UnhandledPromiseRejectionWarning: ReferenceError: WebSocket is not defined
    at Client../src/client.ts.Client._createWebSocket (.../app/index/node_modules/@stomp/stompjs/bundles/stomp.umd.js:420:13)
    at Client.<anonymous> (.../app/index/node_modules/@stomp/stompjs/bundles/stomp.umd.js:361:48)
    at step (.../app/index/node_modules/@stomp/stompjs/bundles/stomp.umd.js:165:23)
    at Object.next (.../app/index/node_modules/@stomp/stompjs/bundles/stomp.umd.js:146:53)
    at fulfilled (.../app/index/node_modules/@stomp/stompjs/bundles/stomp.umd.js:137:58)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
(node:4226) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4226) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I can confirm I've installed websocket using npm.

Any suggestions please?

Thank you.

kum-deepak commented 4 years ago

I have tested with the latest ActiveMQ Artemis. It seems to be working properly.