Search docs.molo17.com
    Configuration guide Connectors

    Stream SQL Server changes to Solace PubSub+

    Gluesync can publish every change of a table as a message on Solace PubSub+, so applications subscribe to the events they need instead of polling the database. This guide streams a SQL Server table to a PubSub+ broker: it prepares a broker user and a queue that keeps the messages, connects the Solace agent, starts the entity, reads the messages of a snapshot and of live changes, then adds a topic prefix and the before image of each change.

    In this guide

    You will learn how to create a client username and a durable queue on the broker, create the Solace PubSub+ target in the Control Plane, choose the topic of an entity, read what Gluesync publishes for inserts, updates, deletes and the snapshot, put a prefix in front of every topic, add the previous values of each row, and recognise the errors for a wrong password and an invalid prefix.

    The steps were run on SQL Server 2022 as the source and Solace PubSub+ Standard as the target.

    Quick information

    Goal

    Publish the changes of a SQL Server table to Solace PubSub+ topics and check every message on the broker

    Audience

    Data engineers and integration developers

    Level

    Intermediate

    Time required

    About 30 minutes

    Area

    Solace PubSub+ broker; Control Plane → Pipelines

    Applies to

    Gluesync 2.3

    Before you begin

    Make sure that:

    1. A SQL Server source is ready for CDC: the database and the table have CDC enabled, and SQL Server Agent runs. See Set up a SQL Server CDC source;

    2. Core Hub can reach the broker on its SMF port, 55555 by default;

    3. You can administer the broker, in PubSub+ Broker Manager or with SEMP, to create a client username and a queue;

    4. You have a Solace client to read messages from a queue, for example a short program with a Solace API.

    How Gluesync publishes

    Every change goes to a topic built from the entity’s Target Topic and the operation. With a Topic prefix, the prefix comes first:

    Change Topic

    Insert

    [<prefix>/]<topic>/insert

    Update, and every row of a Keep and merge snapshot

    [<prefix>/]<topic>/update

    Delete

    [<prefix>/]<topic>/delete, then a second message on the same topic with an empty body (a tombstone)

    Each message carries the property key, for example orders::1003, and a JSON body with the same key and a value that holds after (the row), keys, op (i, u or d), ts_ms and, for live changes, transaction.

    Solace keeps no message for a topic that nobody subscribes to. Create the queue and its subscription before you start the entity, or the snapshot is lost.

    Guide steps

    Create the broker user and a queue

    CLI

    Create a client username for Gluesync and a durable queue that keeps the messages of the topics you will publish. With SEMP v2 on the broker’s management port (8080 here), on the Message VPN default:

    SEMP=http://<broker>:8080/SEMP/v2/config/msgVpns/default
    
    # the VPN checks usernames and passwords stored on the broker
    curl -u admin:<admin password> -X PATCH $SEMP \
      -H 'Content-Type: application/json' -d '{"authenticationBasicType":"internal"}'
    
    # the Gluesync user
    curl -u admin:<admin password> -X POST $SEMP/clientUsernames \
      -H 'Content-Type: application/json' \
      -d '{"clientUsername":"gluesync","password":"<password>","enabled":true}'
    
    # a queue that keeps every change of the orders topic, with or without the prefix used later
    curl -u admin:<admin password> -X POST $SEMP/queues -H 'Content-Type: application/json' \
      -d '{"queueName":"gluesync-orders","accessType":"exclusive","permission":"consume","ingressEnabled":true,"egressEnabled":true}'
    curl -u admin:<admin password> -X POST $SEMP/queues/gluesync-orders/subscriptions \
      -H 'Content-Type: application/json' -d '{"subscriptionTopic":"orders/>"}'
    curl -u admin:<admin password> -X POST $SEMP/queues/gluesync-orders/subscriptions \
      -H 'Content-Type: application/json' -d '{"subscriptionTopic":"acme/erp/>"}'

    You can create the same objects in PubSub+ Broker Manager instead.

    Expected result

    Each call answers "responseCode":200.

    Subscribe the queue to <topic>/>, not to >. The agent also publishes connection checks, messages with the body Ping message on the topic GS_TOPIC, and a queue subscribed to everything collects them too.

    Create the Solace PubSub+ target

    UI

    1. In the pipeline wizard, after the SQL Server source, search for Solace and select Solace PubSub+;

    2. Fill in Host name / Address (here solace), Port (55555), VPN name (default), Username (gluesync) and Password;

    3. Select Test and continue, then name the pipeline, here OrdersToSolace, and select Finish.

    Base settings of the Solace PubSub+ agent with Host name
    Figure 1. The Base settings of the Solace PubSub+ agent.
    Expected result

    The test passes and the target shows gluesync@solace:55555.

    SASL Mechanism and Security Protocol are not used by the Solace agent: the test passed against a broker without TLS while they showed SCRAM-SHA-256 and SASL_SSL. The agent authenticates with the username and password, and uses TLS when you give it a certificate store under Security.

    Add the entity and choose its topic

    UI

    1. Open the pipeline and select Entities +;

    2. In the Object browser, expand dbo and check orders. The entity is created as dbo.orders → orders;

    3. Select the field mapping icon of the entity to check it. Target Topic is the first level of every topic, here orders; type another name to change it;

    4. Select Confirm, then Confirm and continue.

    Field mapping from dbo.orders to the Event Streaming target with Target Topic orders and the four fields order_id
    Figure 2. Target Topic orders: changes go to orders/insert, orders/update and orders/delete.
    Start the entity and read the snapshot

    UI + CLI

    1. Open the entity, select Start, keep Full copy and Keep and merge, and select Start entity;

    2. Read the queue gluesync-orders with your Solace client.

    Entity page of dbo.orders to orders
    Figure 3. The entity is Active, from MS SQL Server to Solace PubSub+.
    Expected result

    One message per row, on orders/update (a Keep and merge snapshot writes updates):

    topic=orders/update key=orders::1001
    {"key":"orders::1001","value":{"after":{"order_id":1001,"customer":"Rossi Costruzioni","status":"open","amount":"1250.00"},"keys":{"order_id":1001},"op":"u","ts_ms":1795776710}}
    Read the live changes

    SQL + CLI

    1. On SQL Server, insert, update and delete a row:

      INSERT INTO dbo.orders VALUES (1004, N'Verdi Logistica', N'open', 99.90);
      UPDATE dbo.orders SET status = N'shipped' WHERE order_id = 1001;
      DELETE FROM dbo.orders WHERE order_id = 1002;
    2. Read the queue again.

    Expected result

    Four messages, in order:

    topic=orders/insert key=orders::1004  {"key":"orders::1004","value":{"after":{...},"keys":{"order_id":1004},"op":"i",...}}
    topic=orders/update key=orders::1001  {"key":"orders::1001","value":{"after":{..."status":"shipped"...},"op":"u",...}}
    topic=orders/delete key=orders::1002  {"key":"orders::1002","value":{"keys":{"order_id":1002},"op":"d",...}}
    topic=orders/delete key=orders::1002  (empty body: the tombstone)
    Add a topic prefix and the before image

    UI + SQL + CLI

    1. On the pipeline page, select the Solace target to edit it, and open Advanced settings;

    2. Select Add property, choose Topic prefix and type acme/erp;

    3. Select Add property again, choose Include before image and switch it on;

    4. Select Test and continue;

    5. On SQL Server, change a row and delete one:

      UPDATE dbo.orders SET amount = 2400.00 WHERE order_id = 1003;
      DELETE FROM dbo.orders WHERE order_id = 1004;
    6. Read the queue.

    Expected result

    The new settings apply to the next changes, without restarting the entity. The topics start with acme/erp, and each message has a before object with the previous values:

    topic=acme/erp/orders/update key=orders::1003
    {"key":"orders::1003","value":{"before":{...,"amount":"2300.00"},"after":{...,"amount":"2400.00"},"keys":{"order_id":1003},"op":"u",...}}
    topic=acme/erp/orders/delete key=orders::1004
    {"key":"orders::1004","value":{"before":{"order_id":1004,"customer":"Verdi Logistica","status":"open","amount":"99.90"},"keys":{"order_id":1004},"op":"d",...}}
    topic=acme/erp/orders/delete key=orders::1004  (empty body)

    The before image comes from the source. SQL Server CDC records the old values of every column, so before is complete. For the other sources, see Specific configuration.

    Verify the result

    You stream SQL Server changes to Solace PubSub+ if:

    • the snapshot rows arrived on <topic>/update, one message per row;

    • an insert, an update and a delete arrived on insert, update and delete, and the delete was followed by a tombstone;

    • with a Topic prefix, every topic starts with the prefix;

    • with Include before image, updates and deletes carry the previous values.

    Troubleshooting

    Problem Possible cause What to do

    Failed to save and …​ did not accept the new credentials: Unauthorized (Host Credentials Update Failed)

    Wrong username or password for the Message VPN

    Check the client username and its password on the broker, then test again

    Failed to save: Invalid topicPrefix "acme/>": Solace topic prefixes cannot contain wildcard characters '*' or '>'.

    The prefix contains a wildcard

    Use plain topic levels, such as acme/erp

    The queue receives nothing

    The queue was created after the changes, or its subscription does not match the topics

    Subscribe the queue to <topic>/> (and <prefix>/<topic>/> with a prefix), then make a new change or run a snapshot

    Messages with the body Ping message on GS_TOPIC

    Connection checks of the agent, collected by a subscription to >

    Subscribe to the topics of your entities only

    Every snapshot message is an update

    A Keep and merge snapshot writes updates

    Treat update as an upsert in the consumers

    before is missing from the messages

    Include before image is off

    Turn it on in the Advanced settings of the target

    A wrong password is reported when you test the connection:

    Solace PubSub+ base settings with the banner Failed to save: the connection was saved
    Figure 4. The error when the broker refuses the credentials.