Streaming of DolphinDB: Cancel all subscriptions on the current node

51 Views Asked by At

I have subscribed multiple stream tables in DolphinDB. Is there any way to unsubscribe them all at one time?

1

There are 1 best solutions below

0
Eva Gao On

Try the following user-defined function to see if this script can meet your requirements:

def ClearAllSubscriptions(){
    if(getStreamingStat().pubTables.rows() > 0){
        do{
            try{
                tableName = getStreamingStat().pubTables[0,0]
                actionName =  getStreamingStat().pubTables[0,3]
                actionName = strReplace(actionName,"[","")
                actionName = strReplace(actionName,"]","")
                arr = actionName.split(',')
            }
            catch(ex){
                print(ex)
            }
            for(actionName in arr){
                try{    
                    print("unsub: " + tableName + ", "  + actionName)
                    unsubscribeTable(tableName=tableName, actionName=actionName)
                    sleep(10)
                }
                catch(ex){
                    print(ex)
                }
            }
    
        }
        while(getStreamingStat().pubTables.rows() != 0)
    }
    print("All subscriptions have been cleared !")
}