---
description: >
  Sample MSSQL service commissioning file

metadata:
  name: Sample MSSQL service
  icon: https://www.cybus.io/wp-content/uploads/2017/10/for-whom1.svg
  provider: cybus
  homepage: https://www.cybus.io
  version: 1.0.0

parameters:
  mssqlHost:
    type: string
    default: 127.0.0.1

  mssqlPort:
    type: integer
    default: 1433

  mssqlUser:
    type: string
    default: sa

  mssqlPassword:
    type: string
    default: SomeLongSecurePassw0rd

  mssqlDatabase:
    type: string
    default: tempdb

  initialReconnectDelay:
    type: integer
    default: 1000

  maxReconnectDelay:
    type: integer
    default: 30000

  factorReconnectDelay:
    type: integer
    default: 2

resources:
  mssqlConnection:
    type: Cybus::Connection
    properties:
      protocol: Mssql
      connection:
        host: !ref mssqlHost
        port: !ref mssqlPort
        username: !ref mssqlUser
        password: !ref mssqlPassword
        database: !ref mssqlDatabase
        connectionStrategy:
          initialDelay: !ref initialReconnectDelay
          maxDelay: !ref maxReconnectDelay
          incrementFactor: !ref factorReconnectDelay

  mssqlQuery1:
    type: Cybus::Endpoint
    properties:
      protocol: Mssql
      connection: !ref mssqlConnection
      subscribe:
        query: 'SELECT name FROM sys.databases'
        # Be very careful with this setting. A low value might overload
        # the database (the unit is milliseconds!).
        interval: 2000

  mssqlQuery2:
    type: Cybus::Endpoint
    properties:
      protocol: Mssql
      connection: !ref mssqlConnection
      write:
        # Here we use the placeholder @someValue. The protocol driver will insert
        # the value from the input JSON message under the key someValue
        query: 'INSERT INTO test (some_column) VALUES (@someValue)'

  mapping:
    type: Cybus::Mapping
    properties:
      mappings:
        - subscribe:
            endpoint: !ref mssqlQuery1
          publish:
            topic: 'system-tables'
        - subscribe:
            topic: 'insert-test'
          publish:
            endpoint: !ref mssqlQuery2
