Last updated:
0 purchases
pip clients msgdistribution
Message Distribution Microservice Client SDK for Dart #
This is a Dart client SDK for pip-services-msgdistribution microservice.
It provides an easy to use abstraction over communication protocols:
HTTP client
Direct client for monolythic deployments
Null client to be used in testing
In addition to the microservice functionality the client SDK supports message templates
that can be configured by client user.
Install #
Add pip-services3-commons-dart and pip_clients_msgdistribution packages
import 'package:pip_services3_commons/pip_services3_commons.dart';
import 'package:pip_clients_msgdistribution/pip_clients_msgdistribution.dart';
copied to clipboard
Use #
Define client configuration parameters that match configuration of the microservice external API
// Client configuration
var config = ConfigParams.fromTuples(
"connection.protocol", "http",
"connection.host", "localhost",
"connection.port", 8080
);
copied to clipboard
Instantiate the client and open connection to the microservice
// Create the client instance
var client = MessageDistributionHttpClientV1(config);
// Connect to the microservice
await client.open(null);
// Work with the microservice
...
});
copied to clipboard
Now the client is ready to perform operations
// Send message to address
var message = MessageV1(
subject: 'Test subject', text: 'Test text', html: 'Test html');
var recipient = RecipientV1(
name: 'Test user',
email: '[email protected]',
phone: '+12345349458');
await client.sendMessage(
null, recipient, message, null, DeliveryMethodV1.All
);
copied to clipboard
// Send message to users
var recipient1 = RecipientV1(id: '1', email: '[email protected]', phone: '+1234567890');
var recipient2 = RecipientV1(id: '2', email: '[email protected]', phone: '+0987654321');
var message = MessageV1(subject: 'Test',
text: 'This is a test message. Please, ignore it');
await client.sendMessages(
null,
[
recipient1,
recipient2
],
message,
null,
DeliveryMethod.All
);
copied to clipboard
To use templates for sent messages you need to put template files
under configured template folder. Inside template you shall use <%= property %> syntax
to insert properties from provided content defined in client configuration and request parameters.
Example of message.txt template
Hello <%= user_name %>!
This is a test message from <%= client_name %> sent on <%= today %>.
Please, ignore it.
copied to clipboard
Example of message.html template
Hello <%= user_name %>!
<p>
This is a test message from <%= client_name %> sent on <%= today %>.
<br/>
Please, ignore it.
</p>
copied to clipboard
Now you can send a message using the templates stored in files.
subjectTemplate, textTemplate and htmlTemplate parameters shall contain the template file paths.
Client will automatically load their content and parse.
// Send msgdistribution message to address using template
var message = MessageV1(subject: File('./templates/message_subject.txt').readAsStringSync(),
text: File('./templates/message.txt').readAsStringSync(),
html: File('./templates/message.html').readAsStringSync());
var recipient = RecipientV1(id: '1', email: '[email protected]', phone: '+1234567890');
var parameters = ConfigParams.fromTuples([
'user_name', 'Somebody',
'today': DateTime.now().toIso8601String()
]);
await client.sendMessage(
null,
recipient,
message,
parameters,
DeliveryMethodV1.All
);
copied to clipboard
This microservice was created and currently maintained by
Sergey Seroukhov
Nuzhnykh Egor.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.