/cta-io

Primary LanguageJavaScriptOtherNOASSERTION

cta-io

Build Status Coverage Status codecov

I/O Modules for Compass Test Automation, One of Libraries in CTA-OSS Framework

General Overview

Overview

This I/O (Input / Output) Module provides communications between CTA-OSS Framework and outsides services via messaging.

Guidelines

We aim to give you brief guidelines here.

  1. Usage
  2. Input / Output
  3. Contracts

1. Usage

cta-io extends Brick (cta-brick). In order to use it, we need to provide a configuration. The cta-io depends on cta-messaging which provides messaging as a tool.

// a full sample code:
const config = {
  tools: [{
    name: 'sample.messaging',
    module: 'cta-messaging',
    properties: {
      provider: 'rabbitmq',
      parameters: {
        url: 'amqp://localhost?heartbeat=60',
      },
    },
  }],
  bricks: [{
    name: 'Receiver',
    module: 'cta-io',
    dependencies: {
      messaging: 'sample.messaging',
    },
    properties: {
      input: {
        queue: 'input.queue',
      },
    },
    publish: [{
      topic: 'sample.topics',
      data: [{}],
    }],
  }, {
    name: 'Sender',
    module: 'cta-io',
    dependencies: {
      messaging: 'sample.messaging',
    },
    properties: {},
    subscribe: [{
      topic: 'sample.topics',
      data: [{}],
    }],
  }],
};

Declaring cta-messaging as cta-io's dependencies

const config = {
  tools: [{
    name: 'sample.messaging',
    module: 'cta-messaging',
    properties: {
      provider: 'rabbitmq',
      parameters: {
        url: 'amqp://localhost?heartbeat=60',
      },
    },
  }],
  ...
};

It declares a tool named "sample.messaging" using cta-messaging module with specified properties.

Declaring Bricks as cta-io

const config = {
  ...
  bricks: [{
    name: 'Receiver',
    module: 'cta-io',
    dependencies: {
      messaging: 'sample.messaging',
    },
    properties: {
      input: {
        queue: 'input.queue',
      },
    },
    publish: [{
      topic: 'sample.topics',
      data: [{}],
    }],
  }, {
    name: 'Sender',
    module: 'cta-io',
    dependencies: {
      messaging: 'sample.messaging',
    },
    properties: {},
    subscribe: [{
      topic: 'sample.topics',
      data: [{}],
    }],
  }],
};

It declares two bricks named "Receiver" and "Sender" using cta-io module with dependencies.messaging named "sample.messaging".

  • "Receiver" Brick using cta-io module
const config = {
  ...
  bricks: [{
    name: 'Receiver',
    module: 'cta-io',
    dependencies: {
      messaging: 'sample.messaging',
    },
    properties: {
      input: {
        queue: 'input.queue',
      },
    },
    publish: [{
      topic: 'sample.topics',
      data: [{}],
    }],
  },
  ...
  ],
};

This "Receiver" Brick subscribes "input.queue" queue via "sample.messaging" and publish a content on "sample.topics" topic.

  • "Sender" Brick using cta-io module
const config = {
  ...
  bricks: [
  ...
  {
    name: 'Sender',
    module: 'cta-io',
    dependencies: {
      messaging: 'sample.messaging',
    },
    properties: {},
    subscribe: [{
      topic: 'sample.topics',
      data: [{}],
    }],
  }],
};

This "Sender" Brick subscribes "sample.topics" topic and processes a content according to the received payload via "sample.messaging".

back to top

2. Input / Output

In configuration, cta-io uses properties to manipulate the content as input / output.

  • properties.input
const config = {
  ...
  bricks: [{
    ...
    properties: {
      input: {
        queue: 'input.queue',
        topic: 'input.topic',
      },
    },
    ...
  }],
};

The properties.input has two fields, queue and topic. They define the name of queue/topic which any content will be consumed from as the input.

  • properties.output
const config = {
  ...
  bricks: [{
    ...
    properties: {
      output: {
        queue: 'output.queue',
        topic: 'output.topic',
      },
    },
    ...
  }],
};

The properties.output has two fields, queue and topic. They define the name of queue/topic which any content will be published to as the output.

back to top

3. Contracts

nature.type nature.quality payload description
message produce { status: 'ok' } produce message { status: 'ok' } on default output queue
message produce { queue: 'sample', message: { status: 'ok' }} produce message on custom queue: 'sample'
message consume { status: 'ok' }
message get { status: 'ok' }
message publish { status: 'ok' } publish message { status: 'ok' } on default exchange and default output topic
message publish { exchange: 'sample.exchange', topic: 'sample.topic', message: { status: 'ok' }} publish message { status: 'ok' } on custom exchange 'sample.exchange' and custom topic 'sample.topic'
message subscribe { topic: 'sample.topic' } subscribe to messages on custom topic 'sample.topic'
message acknowledge { id: '123' } acknowledge consumed message with id '123'

back to top


To Do