Skip to content

Commit

Permalink
concept of logRawCommunication, fixes #25
Browse files Browse the repository at this point in the history
  • Loading branch information
kum-deepak committed Jan 10, 2019
1 parent af98c86 commit eb9bb50
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
47 changes: 47 additions & 0 deletions spec/unit/log-bodies.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {take} from 'rxjs/operators';

import 'jasmine';

import {RxStomp} from '../../src';

import {disconnectRxStompAndEnsure} from '../helpers/helpers';
import {defaultConfig} from '../helpers/rx-stomp-factory';

describe('Log Bodies', () => {
let rxStomp: RxStomp;

// Disconnect and wait till it actually disconnects
afterEach((done) => {
disconnectRxStompAndEnsure(rxStomp, done);
rxStomp = null;
});

it('should trigger webSocketErrors$', (done) => {
const queueName = '/topic/ng-demo-sub';

// Text picked up from https://github.com/stomp-js/stomp-websocket/pull/46
const body = 'Älä sinä yhtään and السابق';
// client.logRawCommunication = true;

const debug = jasmine.createSpy('debug');

rxStomp = new RxStomp();
rxStomp.configure(defaultConfig());

rxStomp.configure({debug, logRawCommunication: true});

rxStomp.watch(queueName).subscribe(() => {
expect(debug.calls.mostRecent().args[0]).toMatch(body);
done();
});

rxStomp.activate();

rxStomp.connected$.pipe(take(1)).subscribe(() => {
rxStomp.publish({destination: queueName, body});
expect(debug.calls.mostRecent().args[0]).toEqual(
'>>> SEND\ndestination:/topic/ng-demo-sub\ncontent-length:37\n\nÄlä sinä yhtään and السابق' + '\0');
});

});
});
12 changes: 12 additions & 0 deletions src/rx-stomp-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ export class RxStompConfig {
*/
public stompVersions?: Versions;

/**
* Set it to log the actual raw communication with the broker.
* When unset, it logs headers of the parsed frames.
*
* Change in this effects from next broker reconnect.
*
* **Caution: this assumes that frames only have valid UTF8 strings.**
*
* Maps to: [Client#logRawCommunication]{@link Client#logRawCommunication}.
*/
public logRawCommunication?: boolean;

/** Enable client debugging? */
public debug?: debugFnType;

Expand Down

0 comments on commit eb9bb50

Please sign in to comment.