
// Configure rabbit mq consumer settings
def set_rabbitmq = { instance, enableConsumer, serviceUri, userName, userPassword, applicationId, queueName ->
      def rabbitmq_consumer = instance.getDescriptor('org.jenkinsci.plugins.rabbitmqconsumer.GlobalRabbitmqConfiguration')
      def consumeItems = rabbitmq_consumer.getConsumeItems()
      if (consumeItems == null || consumeItems.empty) {
          consumeItems = []
      } else {
        consumeItems.removeAll { it.getAppId().equals(applicationId) && it.getQueueName().equals(queueName) }
      }
      consumeItems.add(new org.jenkinsci.plugins.rabbitmqconsumer.RabbitmqConsumeItem(applicationId, queueName))
      rabbitmq_consumer.setEnableConsumer(enableConsumer)
      rabbitmq_consumer.setServiceUri(serviceUri)
      rabbitmq_consumer.setUserName(userName)
      rabbitmq_consumer.setUserPassword(userPassword)
      rabbitmq_consumer.setConsumeItems(consumeItems)
      rabbitmq_consumer.save()
}

