github.com/Jeffail/benthos/v3@v3.65.0/lib/output/azure_table_storage.go (about)

     1  package output
     2  
     3  import (
     4  	"github.com/Jeffail/benthos/v3/internal/docs"
     5  	"github.com/Jeffail/benthos/v3/lib/log"
     6  	"github.com/Jeffail/benthos/v3/lib/message/batch"
     7  	"github.com/Jeffail/benthos/v3/lib/metrics"
     8  	"github.com/Jeffail/benthos/v3/lib/output/writer"
     9  	"github.com/Jeffail/benthos/v3/lib/types"
    10  )
    11  
    12  //------------------------------------------------------------------------------
    13  
    14  func init() {
    15  	Constructors[TypeAzureTableStorage] = TypeSpec{
    16  		constructor: fromSimpleConstructor(NewAzureTableStorage),
    17  		Status:      docs.StatusBeta,
    18  		Version:     "3.36.0",
    19  		Summary: `
    20  Stores message parts in an Azure Table Storage table.`,
    21  		Description: `
    22  Only one authentication method is required, ` + "`storage_connection_string`" + ` or ` + "`storage_account` and `storage_access_key`" + `. If both are set then the ` + "`storage_connection_string`" + ` is given priority.
    23  
    24  In order to set the ` + "`table_name`" + `,  ` + "`partition_key`" + ` and ` + "`row_key`" + `
    25  you can use function interpolations described [here](/docs/configuration/interpolation#bloblang-queries), which are
    26  calculated per message of a batch.
    27  
    28  If the ` + "`properties`" + ` are not set in the config, all the ` + "`json`" + ` fields
    29  are marshaled and stored in the table, which will be created if it does not exist.
    30  
    31  The ` + "`object`" + ` and ` + "`array`" + ` fields are marshaled as strings. e.g.:
    32  
    33  The JSON message:
    34  ` + "```json" + `
    35  {
    36    "foo": 55,
    37    "bar": {
    38      "baz": "a",
    39      "bez": "b"
    40    },
    41    "diz": ["a", "b"]
    42  }
    43  ` + "```" + `
    44  
    45  Will store in the table the following properties:
    46  ` + "```yml" + `
    47  foo: '55'
    48  bar: '{ "baz": "a", "bez": "b" }'
    49  diz: '["a", "b"]'
    50  ` + "```" + `
    51  
    52  It's also possible to use function interpolations to get or transform the properties values, e.g.:
    53  
    54  ` + "```yml" + `
    55  properties:
    56    device: '${! json("device") }'
    57    timestamp: '${! json("timestamp") }'
    58  ` + "```" + ``,
    59  		Async:   true,
    60  		Batches: true,
    61  		FieldSpecs: docs.FieldSpecs{
    62  			docs.FieldCommon(
    63  				"storage_account",
    64  				"The storage account to upload messages to. This field is ignored if `storage_connection_string` is set.",
    65  			),
    66  			docs.FieldCommon(
    67  				"storage_access_key",
    68  				"The storage account access key. This field is ignored if `storage_connection_string` is set.",
    69  			),
    70  			docs.FieldCommon(
    71  				"storage_connection_string",
    72  				"A storage account connection string. This field is required if `storage_account` and `storage_access_key` are not set.",
    73  			),
    74  			docs.FieldCommon("table_name", "The table to store messages into.",
    75  				`${!meta("kafka_topic")}`,
    76  			).IsInterpolated(),
    77  			docs.FieldCommon("partition_key", "The partition key.",
    78  				`${!json("date")}`,
    79  			).IsInterpolated(),
    80  			docs.FieldCommon("row_key", "The row key.",
    81  				`${!json("device")}-${!uuid_v4()}`,
    82  			).IsInterpolated(),
    83  			docs.FieldString("properties", "A map of properties to store into the table.").IsInterpolated().Map(),
    84  			docs.FieldAdvanced("insert_type", "Type of insert operation").HasOptions(
    85  				"INSERT", "INSERT_MERGE", "INSERT_REPLACE",
    86  			).IsInterpolated(),
    87  			docs.FieldCommon("max_in_flight",
    88  				"The maximum number of messages to have in flight at a given time. Increase this to improve throughput."),
    89  			docs.FieldAdvanced("timeout", "The maximum period to wait on an upload before abandoning it and reattempting."),
    90  			batch.FieldSpec(),
    91  		},
    92  		Categories: []Category{
    93  			CategoryServices,
    94  			CategoryAzure,
    95  		},
    96  	}
    97  
    98  	Constructors[TypeTableStorage] = TypeSpec{
    99  		constructor: fromSimpleConstructor(newDeprecatedTableStorage),
   100  		Status:      docs.StatusDeprecated,
   101  		Summary:     "This component has been renamed to [`azure_table_storage`](/docs/components/outputs/azure_table_storage).",
   102  		Async:       true,
   103  		Batches:     true,
   104  		FieldSpecs: docs.FieldSpecs{
   105  			docs.FieldCommon(
   106  				"storage_account",
   107  				"The storage account to upload messages to. This field is ignored if `storage_connection_string` is set.",
   108  			),
   109  			docs.FieldCommon(
   110  				"storage_access_key",
   111  				"The storage account access key. This field is ignored if `storage_connection_string` is set.",
   112  			),
   113  			docs.FieldCommon(
   114  				"storage_connection_string",
   115  				"A storage account connection string. This field is required if `storage_account` and `storage_access_key` are not set.",
   116  			),
   117  			docs.FieldCommon("table_name", "The table to store messages into.",
   118  				`${!meta("kafka_topic")}`,
   119  			).IsInterpolated(),
   120  			docs.FieldCommon("partition_key", "The partition key.",
   121  				`${!json("date")}`,
   122  			).IsInterpolated(),
   123  			docs.FieldCommon("row_key", "The row key.",
   124  				`${!json("device")}-${!uuid_v4()}`,
   125  			).IsInterpolated(),
   126  			docs.FieldString("properties", "A map of properties to store into the table.").IsInterpolated().Map(),
   127  			docs.FieldAdvanced("insert_type", "Type of insert operation").HasOptions(
   128  				"INSERT", "INSERT_MERGE", "INSERT_REPLACE",
   129  			).IsInterpolated(),
   130  			docs.FieldCommon("max_in_flight",
   131  				"The maximum number of messages to have in flight at a given time. Increase this to improve throughput."),
   132  			docs.FieldAdvanced("timeout", "The maximum period to wait on an upload before abandoning it and reattempting."),
   133  			batch.FieldSpec(),
   134  		},
   135  		Categories: []Category{
   136  			CategoryServices,
   137  			CategoryAzure,
   138  		},
   139  	}
   140  }
   141  
   142  //------------------------------------------------------------------------------
   143  
   144  // NewAzureTableStorage creates a new NewAzureTableStorage output type.
   145  func NewAzureTableStorage(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) {
   146  	tableStorage, err := writer.NewAzureTableStorageV2(conf.AzureTableStorage, mgr, log, stats)
   147  	if err != nil {
   148  		return nil, err
   149  	}
   150  	w, err := NewAsyncWriter(
   151  		TypeAzureTableStorage, conf.AzureTableStorage.MaxInFlight, tableStorage, log, stats,
   152  	)
   153  	if err != nil {
   154  		return nil, err
   155  	}
   156  	return NewBatcherFromConfig(conf.AzureTableStorage.Batching, w, mgr, log, stats)
   157  }
   158  
   159  func newDeprecatedTableStorage(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) {
   160  	tableStorage, err := writer.NewAzureTableStorageV2(conf.TableStorage, mgr, log, stats)
   161  	if err != nil {
   162  		return nil, err
   163  	}
   164  	var w Type
   165  	if conf.TableStorage.MaxInFlight == 1 {
   166  		w, err = NewWriter(
   167  			TypeTableStorage, tableStorage, log, stats,
   168  		)
   169  	} else {
   170  		w, err = NewAsyncWriter(
   171  			TypeTableStorage, conf.TableStorage.MaxInFlight, tableStorage, log, stats,
   172  		)
   173  	}
   174  	if err != nil {
   175  		return nil, err
   176  	}
   177  	return NewBatcherFromConfig(conf.TableStorage.Batching, w, mgr, log, stats)
   178  }
   179  
   180  //------------------------------------------------------------------------------