const {subscribeToMessageType} = require('./messageHandlers')
const {publish} = require('../modules/rabbitSender')

function publishMessage(exchange, routingKey, messageBody, throwIfFail = true) {
  publish(exchange, routingKey, messageBody, throwIfFail)
}

/**
 * @module exchange
 * @memberOf module:@unitybase/messaging
 */
module.exports = {
  subscribeToMessageType,
  /**
   * Sends message to RabbitMQ to the exchange that forwards message to marketplace
   * @method publishMessage
   * @param {string} exchange
   *   Type of the message to be sent (this will be the second part of routing key)
   * @param {string} routingKey
   *   Routing key for the published message
   * @param {object|string} messageBody
   *   Message to be sent - it is expected to be JSON serializable object
   *   or string that contain pre-serialized JSON
   * @param {boolean} [throwIfFail]
   *   For important messages, like server-to-service communication, pass "true" for this
   *   parameter.
   *   For non-important messages, like push notification of clients, do not pass this parameter, or pass "false",
   *   so that server call won't crash, even, if message sending failed.
   */
  publishMessage
}