unsubscribeTable

Syntax

unsubscribeTable([server], tableName, [actionName], [removeOffset=true], [raftGroup])

Details

Stop subscribing to data from the publisher. All messages of the topic in the message queue of the execution thread will be deleted.

When unsubscribeTable is called, unprocessed messages in the queue of the stream execution thread will be deleted.

Parameters

server (optional) is a string indicating the alias of a server or the xdb connection to a server where the stream table is located. If it is unspecified or an empty string (""), it means the local instance.

tableName is a string indicating the name of the shared stream table to be unsubscribed on the aforementioned server.

actionName (optional) is a string indicating the name assigned to the handler. It can have letters, digits and underscores. If actionName is specified when the subscription is initiated, it must be specified in unsubscribeTable as well.

removeOffset (optional) is a Boolean value indicating whether to delete the offset of the latest record that has been calculated. (set persistOffset = true in subscribeTable to keep the offset of latest record.)

raftGroup (optional) is the raft group ID specified in function subscribeTable. Specify it in unsubscribeTable to disable high availability on the subscriber.

Note:
The command unsubscribeTable can only be executed on the leader node if the parameter raftGroup is specified.

Returns

None.

Examples

The following examples show how to subscribe to and unsubscribe from a stream table. In Example 1, publishing and subscribing are done on the same node. In Example 2, the publisher and the subscriber are on different nodes.

Example 1: Create shared stream table "trades" and table "trades2" on the local node to store the subscribed data.

t = streamTable(100:0, `date`time`sym`qty`price`exch, [DATE,TIME,SYMBOL,INT,DOUBLE,SYMBOL])
share t as trades
t2 = streamTable(100:0, `date`time`sym`qty`price`exch, [DATE,TIME,SYMBOL,INT,DOUBLE,SYMBOL])
share t2 as trades2
t = NULL
t2 = NULL

Subscribe to table "trades", then insert a record into "trades". Table "trades2" receives the record.

subscribeTable(tableName="trades", actionName="sub1", handler=trades2)
insert into trades values(2024.01.01, 09:30:00.000, `AAPL, 100, 120.5, `NASDAQ)
sleep(100)
select count(*) from trades2
// output: 1

To unsubscribe from table "trades":

unsubscribeTable(tableName="trades", actionName="sub1")

Example 2: The publisher and the subscriber are on different nodes. This example must run on two nodes, and the publish/subscribe port of the publisher is 8902. A node cannot connect to itself through xdb.

Create table "trades" on the publisher.

t=streamTable(100:0,`date`time`sym`qty`price`exch,[DATE,TIME,SYMBOL,INT,DOUBLE,SYMBOL])
share t as trades
t=NULL

Create table "trades2" on the subscriber to stream data from table "trades" from the publisher:

t=streamTable(100:0,`date`time`sym`qty`price`exch,[DATE,TIME,SYMBOL,INT,DOUBLE,SYMBOL])
share t as trades2
t=NULL
h=xdb("localhost",8902)
subscribeTable(server=h, tableName="trades", actionName="sub1", handler=trades2);
// output: localhost:8902:node1/trades/sub1

To unsubscribe from table "trades" on the subscriber:

unsubscribeTable(server=h, tableName="trades", actionName="sub1")