Mountebank and IBM MQ connection

80 views
Skip to first unread message

Bibhudutta Dash

unread,
Jun 9, 2021, 6:37:27 AM6/9/21
to mountebank-discuss
HI All,
I have got a IBM MQ url which i want get it configured with the present http mountebank project created, can someone please help me get the same implemented:

IBM MQ Get Details.
var request = require('request');
var options = {
  'method': 'GET',
  'url': '***IBM MQ URL***',
  'headers': {
    'Authorization': 'Basic YmhhdnlhcmpncGw6NU1LMzRDeXpLd1llcHowU3FDaHBMTW9jb1FlUS1XNDZFaGZqLWlfQWswOTg='
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

Mountebank file and folder structure on VS Code:
  1. Create a folder in VS Code
  2. Type the below commands in Terminal,

npm init

npm install -save mountebank

  1. Edit the file package.json as below,
  2. {
  3.   "name": "mountebank-workspace",
  4.   "version": "1.0.0",
  5.   "description": "",
  6.   "main": "index.js",
  7.   "scripts": {
  8.     "start": "node src/index.js"
  9.   },
  10.   "author": "",
  11.   "license": "ISC",
  12.   "dependencies": {
  13.     "mountebank": "^2.2.1",
  14.     "node-fetch": "^2.6.0"
  15.   }
  16. }
  17.  

 

4. Create a folder called src and add the below files ,

  1. Settings.js

 

  1. module.exports = {
  2.     port: 5000,
  3.     hello_service_port: 5001,
  4.     customer_service_port: 5002
  5. }

 

2.index.js – creating a mountebank server

 

const mb = require('mountebank');

const settings = require('./settings');

const helloService = require('./hello-service');

 

const mbServerInstance = mb.create({

        port: settings.port,

        pidfile: '../mb.pid',

        logfile: '../mb.log',

        protofile: '../protofile.json',

        ipWhitelist: ['*']

    });

 

    

mbServerInstance.then(function() {

    helloService.addService();

});

 

3.mountebank-helper.js – code to call the server

 

const fetch = require('node-fetch');

const settings = require('./settings');

 

function postImposter(body) {

    const url = `http://127.0.0.1:${settings.port}/imposters`;

 

    return fetch(url, {

                    method:'POST',

                    headers: { 'Content-Type': 'application/json' },

                    body: JSON.stringify(body)

                });

}

 

module.exports = { postImposter };

 

4.hello-service.js  - building an imposter

 

const mbHelper = require('./mountebank-helper');

const settings = require('./settings');

 

function addService() {

    const response = { message: "hello world" }

 

    const stubs = [

        {

            predicates: [ {

                equals: {

                    method: "GET",

                    "path": "/"

                }

            }],

            responses: [

                {

                    is: {

                        statusCode: 200,

                        headers: {

                            "Content-Type": "application/json"

                        },

                        body: JSON.stringify(response)

                    }

                }

            ]

        }

    ];

 

    const imposter = {

        port: settings.hello_service_port,

        protocol: 'http',

        stubs: stubs

    };

 

    return mbHelper.postImposter(imposter);

}

 

module.exports = { addService };

 

5.Type the below command in Terminal,

npm start

6. Open Postman – testing starts here

7.  Send the GET request http://localhost:5001/

8. Response will be displayed as ,

 { message: "hello world" }


Please help me by implementing this stepwise so that i can get the thing implemented.

Thanks in Advance!!!

Bibhudutta Dash

unread,
Jun 11, 2021, 3:17:08 AM6/11/21
to mountebank-discuss
Hi All,
Please help on guiding me with the problems statement here.
@Brandon, looking forward for your response.
Thanks and Regards,
Bibhu

Bibhudutta Dash

unread,
Jun 14, 2021, 2:03:10 AM6/14/21
to mountebank-discuss
Hi All,
Please help in achieving the above stated problem.
Thanks and Regards,
Bibhu

Reply all
Reply to author
Forward
0 new messages