[{"data":1,"prerenderedAt":1626},["ShallowReactive",2],{"docs:/docs/concepts/topics":3},{"id":4,"title":5,"body":6,"description":1619,"extension":1620,"meta":1621,"navigation":64,"path":1622,"seo":1623,"stem":1624,"__hash__":1625},"docs/docs/concepts/topics.md","Topics & Pub/Sub",{"type":7,"value":8,"toc":1605},"minimark",[9,13,17,22,25,586,590,593,621,626,647,651,654,658,661,753,757,760,838,842,845,1104,1108,1117,1137,1462,1466,1469,1569,1573,1601],[10,11,5],"h1",{"id":12},"topics-pubsub",[14,15,16],"p",{},"Topics are the foundation of NoLag's messaging system. Learn how to use topics for efficient pub/sub communication.",[18,19,21],"h2",{"id":20},"what-are-topics","What are Topics?",[14,23,24],{},"Topics are named channels that clients can subscribe to and publish messages on. When a message is published to a topic, all subscribed clients receive it in real-time.",[26,27,28,342,453],"code-tabs",{},[29,30,36],"pre",{"className":31,"code":32,"filename":33,"language":34,"meta":35,"style":35},"language-ts shiki shiki-themes github-light github-dark","import { NoLag } from '@nolag/js-sdk'\n\nconst client = NoLag('your_access_token')\nawait client.connect()\n\nconst room = client.setApp('my-app').setRoom('general')\n\n// Subscribe to a topic\nroom.subscribe('notifications')\n\n// Listen for messages (data + meta)\nroom.on('notifications', (data, meta) => {\n  console.log('Received:', data)\n  console.log('Is replay:', meta.isReplay)\n  console.log('Message ID:', meta.msgId)\n  if (meta.filter) console.log('Filter:', meta.filter)\n})\n\n// Publish a message\nroom.emit('notifications', {\n  type: 'alert',\n  message: 'New notification!'\n})\n","TypeScript","ts","",[37,38,39,59,66,92,107,112,145,150,157,173,178,184,218,235,250,265,284,290,295,301,316,328,337],"code",{"__ignoreMap":35},[40,41,44,48,52,55],"span",{"class":42,"line":43},"line",1,[40,45,47],{"class":46},"szBVR","import",[40,49,51],{"class":50},"sVt8B"," { NoLag } ",[40,53,54],{"class":46},"from",[40,56,58],{"class":57},"sZZnC"," '@nolag/js-sdk'\n",[40,60,62],{"class":42,"line":61},2,[40,63,65],{"emptyLinePlaceholder":64},true,"\n",[40,67,69,72,76,79,83,86,89],{"class":42,"line":68},3,[40,70,71],{"class":46},"const",[40,73,75],{"class":74},"sj4cs"," client",[40,77,78],{"class":46}," =",[40,80,82],{"class":81},"sScJk"," NoLag",[40,84,85],{"class":50},"(",[40,87,88],{"class":57},"'your_access_token'",[40,90,91],{"class":50},")\n",[40,93,95,98,101,104],{"class":42,"line":94},4,[40,96,97],{"class":46},"await",[40,99,100],{"class":50}," client.",[40,102,103],{"class":81},"connect",[40,105,106],{"class":50},"()\n",[40,108,110],{"class":42,"line":109},5,[40,111,65],{"emptyLinePlaceholder":64},[40,113,115,117,120,122,124,127,129,132,135,138,140,143],{"class":42,"line":114},6,[40,116,71],{"class":46},[40,118,119],{"class":74}," room",[40,121,78],{"class":46},[40,123,100],{"class":50},[40,125,126],{"class":81},"setApp",[40,128,85],{"class":50},[40,130,131],{"class":57},"'my-app'",[40,133,134],{"class":50},").",[40,136,137],{"class":81},"setRoom",[40,139,85],{"class":50},[40,141,142],{"class":57},"'general'",[40,144,91],{"class":50},[40,146,148],{"class":42,"line":147},7,[40,149,65],{"emptyLinePlaceholder":64},[40,151,153],{"class":42,"line":152},8,[40,154,156],{"class":155},"sJ8bj","// Subscribe to a topic\n",[40,158,160,163,166,168,171],{"class":42,"line":159},9,[40,161,162],{"class":50},"room.",[40,164,165],{"class":81},"subscribe",[40,167,85],{"class":50},[40,169,170],{"class":57},"'notifications'",[40,172,91],{"class":50},[40,174,176],{"class":42,"line":175},10,[40,177,65],{"emptyLinePlaceholder":64},[40,179,181],{"class":42,"line":180},11,[40,182,183],{"class":155},"// Listen for messages (data + meta)\n",[40,185,187,189,192,194,196,199,203,206,209,212,215],{"class":42,"line":186},12,[40,188,162],{"class":50},[40,190,191],{"class":81},"on",[40,193,85],{"class":50},[40,195,170],{"class":57},[40,197,198],{"class":50},", (",[40,200,202],{"class":201},"s4XuR","data",[40,204,205],{"class":50},", ",[40,207,208],{"class":201},"meta",[40,210,211],{"class":50},") ",[40,213,214],{"class":46},"=>",[40,216,217],{"class":50}," {\n",[40,219,221,224,227,229,232],{"class":42,"line":220},13,[40,222,223],{"class":50},"  console.",[40,225,226],{"class":81},"log",[40,228,85],{"class":50},[40,230,231],{"class":57},"'Received:'",[40,233,234],{"class":50},", data)\n",[40,236,238,240,242,244,247],{"class":42,"line":237},14,[40,239,223],{"class":50},[40,241,226],{"class":81},[40,243,85],{"class":50},[40,245,246],{"class":57},"'Is replay:'",[40,248,249],{"class":50},", meta.isReplay)\n",[40,251,253,255,257,259,262],{"class":42,"line":252},15,[40,254,223],{"class":50},[40,256,226],{"class":81},[40,258,85],{"class":50},[40,260,261],{"class":57},"'Message ID:'",[40,263,264],{"class":50},", meta.msgId)\n",[40,266,268,271,274,276,278,281],{"class":42,"line":267},16,[40,269,270],{"class":46},"  if",[40,272,273],{"class":50}," (meta.filter) console.",[40,275,226],{"class":81},[40,277,85],{"class":50},[40,279,280],{"class":57},"'Filter:'",[40,282,283],{"class":50},", meta.filter)\n",[40,285,287],{"class":42,"line":286},17,[40,288,289],{"class":50},"})\n",[40,291,293],{"class":42,"line":292},18,[40,294,65],{"emptyLinePlaceholder":64},[40,296,298],{"class":42,"line":297},19,[40,299,300],{"class":155},"// Publish a message\n",[40,302,304,306,309,311,313],{"class":42,"line":303},20,[40,305,162],{"class":50},[40,307,308],{"class":81},"emit",[40,310,85],{"class":50},[40,312,170],{"class":57},[40,314,315],{"class":50},", {\n",[40,317,319,322,325],{"class":42,"line":318},21,[40,320,321],{"class":50},"  type: ",[40,323,324],{"class":57},"'alert'",[40,326,327],{"class":50},",\n",[40,329,331,334],{"class":42,"line":330},22,[40,332,333],{"class":50},"  message: ",[40,335,336],{"class":57},"'New notification!'\n",[40,338,340],{"class":42,"line":339},23,[40,341,289],{"class":50},[29,343,348],{"className":344,"code":345,"filename":346,"language":347,"meta":35,"style":35},"language-python shiki shiki-themes github-light github-dark","from nolag import NoLag\n\nclient = NoLag('your_access_token')\nawait client.connect()\n\nroom = client.set_app('my-app').set_room('general')\n\n# Subscribe to a topic\nawait room.subscribe('notifications')\n\n# Listen for messages (data + meta)\ndef handle_notification(data, meta):\n    print('Received:', data)\n    print('Is replay:', meta.is_replay)\n\nroom.on('notifications', handle_notification)\n\n# Publish a message\nawait room.emit('notifications', {\n    'type': 'alert',\n    'message': 'New notification!'\n})\n","Python","python",[37,349,350,355,359,364,369,373,378,382,387,392,396,401,406,411,416,420,425,429,434,439,444,449],{"__ignoreMap":35},[40,351,352],{"class":42,"line":43},[40,353,354],{},"from nolag import NoLag\n",[40,356,357],{"class":42,"line":61},[40,358,65],{"emptyLinePlaceholder":64},[40,360,361],{"class":42,"line":68},[40,362,363],{},"client = NoLag('your_access_token')\n",[40,365,366],{"class":42,"line":94},[40,367,368],{},"await client.connect()\n",[40,370,371],{"class":42,"line":109},[40,372,65],{"emptyLinePlaceholder":64},[40,374,375],{"class":42,"line":114},[40,376,377],{},"room = client.set_app('my-app').set_room('general')\n",[40,379,380],{"class":42,"line":147},[40,381,65],{"emptyLinePlaceholder":64},[40,383,384],{"class":42,"line":152},[40,385,386],{},"# Subscribe to a topic\n",[40,388,389],{"class":42,"line":159},[40,390,391],{},"await room.subscribe('notifications')\n",[40,393,394],{"class":42,"line":175},[40,395,65],{"emptyLinePlaceholder":64},[40,397,398],{"class":42,"line":180},[40,399,400],{},"# Listen for messages (data + meta)\n",[40,402,403],{"class":42,"line":186},[40,404,405],{},"def handle_notification(data, meta):\n",[40,407,408],{"class":42,"line":220},[40,409,410],{},"    print('Received:', data)\n",[40,412,413],{"class":42,"line":237},[40,414,415],{},"    print('Is replay:', meta.is_replay)\n",[40,417,418],{"class":42,"line":252},[40,419,65],{"emptyLinePlaceholder":64},[40,421,422],{"class":42,"line":267},[40,423,424],{},"room.on('notifications', handle_notification)\n",[40,426,427],{"class":42,"line":286},[40,428,65],{"emptyLinePlaceholder":64},[40,430,431],{"class":42,"line":292},[40,432,433],{},"# Publish a message\n",[40,435,436],{"class":42,"line":297},[40,437,438],{},"await room.emit('notifications', {\n",[40,440,441],{"class":42,"line":303},[40,442,443],{},"    'type': 'alert',\n",[40,445,446],{"class":42,"line":318},[40,447,448],{},"    'message': 'New notification!'\n",[40,450,451],{"class":42,"line":330},[40,452,289],{},[29,454,459],{"className":455,"code":456,"filename":457,"language":458,"meta":35,"style":35},"language-go shiki shiki-themes github-light github-dark","package main\n\nimport (\n    \"fmt\"\n\n    nolag \"github.com/NoLagApp/go-sdk\"\n)\n\nfunc main() {\n    client := nolag.New(\"your_access_token\")\n    client.Connect()\n\n    room := client.SetApp(\"my-app\").SetRoom(\"general\")\n\n    // Subscribe to a topic with message handler\n    room.Subscribe(\"notifications\", func(data any, meta nolag.MessageMeta) {\n        fmt.Println(\"Received:\", data)\n        fmt.Println(\"Is replay:\", meta.IsReplay)\n    })\n\n    // Publish a message\n    room.Emit(\"notifications\", map[string]any{\n        \"type\":    \"alert\",\n        \"message\": \"New notification!\",\n    })\n}\n","Go","go",[37,460,461,466,470,475,480,484,489,493,497,502,507,512,516,521,525,530,535,540,545,550,554,559,564,569,575,580],{"__ignoreMap":35},[40,462,463],{"class":42,"line":43},[40,464,465],{},"package main\n",[40,467,468],{"class":42,"line":61},[40,469,65],{"emptyLinePlaceholder":64},[40,471,472],{"class":42,"line":68},[40,473,474],{},"import (\n",[40,476,477],{"class":42,"line":94},[40,478,479],{},"    \"fmt\"\n",[40,481,482],{"class":42,"line":109},[40,483,65],{"emptyLinePlaceholder":64},[40,485,486],{"class":42,"line":114},[40,487,488],{},"    nolag \"github.com/NoLagApp/go-sdk\"\n",[40,490,491],{"class":42,"line":147},[40,492,91],{},[40,494,495],{"class":42,"line":152},[40,496,65],{"emptyLinePlaceholder":64},[40,498,499],{"class":42,"line":159},[40,500,501],{},"func main() {\n",[40,503,504],{"class":42,"line":175},[40,505,506],{},"    client := nolag.New(\"your_access_token\")\n",[40,508,509],{"class":42,"line":180},[40,510,511],{},"    client.Connect()\n",[40,513,514],{"class":42,"line":186},[40,515,65],{"emptyLinePlaceholder":64},[40,517,518],{"class":42,"line":220},[40,519,520],{},"    room := client.SetApp(\"my-app\").SetRoom(\"general\")\n",[40,522,523],{"class":42,"line":237},[40,524,65],{"emptyLinePlaceholder":64},[40,526,527],{"class":42,"line":252},[40,528,529],{},"    // Subscribe to a topic with message handler\n",[40,531,532],{"class":42,"line":267},[40,533,534],{},"    room.Subscribe(\"notifications\", func(data any, meta nolag.MessageMeta) {\n",[40,536,537],{"class":42,"line":286},[40,538,539],{},"        fmt.Println(\"Received:\", data)\n",[40,541,542],{"class":42,"line":292},[40,543,544],{},"        fmt.Println(\"Is replay:\", meta.IsReplay)\n",[40,546,547],{"class":42,"line":297},[40,548,549],{},"    })\n",[40,551,552],{"class":42,"line":303},[40,553,65],{"emptyLinePlaceholder":64},[40,555,556],{"class":42,"line":318},[40,557,558],{},"    // Publish a message\n",[40,560,561],{"class":42,"line":330},[40,562,563],{},"    room.Emit(\"notifications\", map[string]any{\n",[40,565,566],{"class":42,"line":339},[40,567,568],{},"        \"type\":    \"alert\",\n",[40,570,572],{"class":42,"line":571},24,[40,573,574],{},"        \"message\": \"New notification!\",\n",[40,576,578],{"class":42,"line":577},25,[40,579,549],{},[40,581,583],{"class":42,"line":582},26,[40,584,585],{},"}\n",[18,587,589],{"id":588},"topic-naming","Topic Naming",[14,591,592],{},"Topics use a hierarchical naming convention with forward slashes as separators:",[594,595,596,603,609,615],"ul",{},[597,598,599,602],"li",{},[37,600,601],{},"chat/general"," - General chat room",[597,604,605,608],{},[37,606,607],{},"chat/room-1"," - Specific chat room",[597,610,611,614],{},[37,612,613],{},"users/123/notifications"," - User-specific notifications",[597,616,617,620],{},[37,618,619],{},"orders/status/processing"," - Order status updates",[622,623,625],"h3",{"id":624},"naming-best-practices","Naming Best Practices",[594,627,628,631,634,637],{},[597,629,630],{},"Use lowercase letters and hyphens",[597,632,633],{},"Keep hierarchy logical and consistent",[597,635,636],{},"Include identifiers for user/resource-specific topics",[597,638,639,640,643,644],{},"Avoid special characters except ",[37,641,642],{},"/"," and ",[37,645,646],{},"-",[18,648,650],{"id":649},"wildcards","Wildcards",[14,652,653],{},"NoLag supports wildcard subscriptions for flexible topic matching:",[622,655,657],{"id":656},"single-level-wildcard","Single-Level Wildcard (+)",[14,659,660],{},"Matches exactly one level in the topic hierarchy:",[26,662,663,696,721],{},[29,664,666],{"className":31,"code":665,"filename":33,"language":34,"meta":35,"style":35},"// Subscribe to all room messages\nroom.subscribe('chat/+/messages')\n// Matches: chat/room-1/messages, chat/room-2/messages\n// Does NOT match: chat/messages, chat/room-1/private/messages\n",[37,667,668,673,686,691],{"__ignoreMap":35},[40,669,670],{"class":42,"line":43},[40,671,672],{"class":155},"// Subscribe to all room messages\n",[40,674,675,677,679,681,684],{"class":42,"line":61},[40,676,162],{"class":50},[40,678,165],{"class":81},[40,680,85],{"class":50},[40,682,683],{"class":57},"'chat/+/messages'",[40,685,91],{"class":50},[40,687,688],{"class":42,"line":68},[40,689,690],{"class":155},"// Matches: chat/room-1/messages, chat/room-2/messages\n",[40,692,693],{"class":42,"line":94},[40,694,695],{"class":155},"// Does NOT match: chat/messages, chat/room-1/private/messages\n",[29,697,699],{"className":344,"code":698,"filename":346,"language":347,"meta":35,"style":35},"# Subscribe to all room messages\nawait room.subscribe('chat/+/messages')\n# Matches: chat/room-1/messages, chat/room-2/messages\n# Does NOT match: chat/messages, chat/room-1/private/messages\n",[37,700,701,706,711,716],{"__ignoreMap":35},[40,702,703],{"class":42,"line":43},[40,704,705],{},"# Subscribe to all room messages\n",[40,707,708],{"class":42,"line":61},[40,709,710],{},"await room.subscribe('chat/+/messages')\n",[40,712,713],{"class":42,"line":68},[40,714,715],{},"# Matches: chat/room-1/messages, chat/room-2/messages\n",[40,717,718],{"class":42,"line":94},[40,719,720],{},"# Does NOT match: chat/messages, chat/room-1/private/messages\n",[29,722,724],{"className":455,"code":723,"filename":457,"language":458,"meta":35,"style":35},"// Subscribe to all room messages with handler\nroom.Subscribe(\"chat/+/messages\", func(data any, meta nolag.MessageMeta) {\n    fmt.Println(\"Received:\", data)\n})\n// Matches: chat/room-1/messages, chat/room-2/messages\n// Does NOT match: chat/messages, chat/room-1/private/messages\n",[37,725,726,731,736,741,745,749],{"__ignoreMap":35},[40,727,728],{"class":42,"line":43},[40,729,730],{},"// Subscribe to all room messages with handler\n",[40,732,733],{"class":42,"line":61},[40,734,735],{},"room.Subscribe(\"chat/+/messages\", func(data any, meta nolag.MessageMeta) {\n",[40,737,738],{"class":42,"line":68},[40,739,740],{},"    fmt.Println(\"Received:\", data)\n",[40,742,743],{"class":42,"line":94},[40,744,289],{},[40,746,747],{"class":42,"line":109},[40,748,690],{},[40,750,751],{"class":42,"line":114},[40,752,695],{},[622,754,756],{"id":755},"multi-level-wildcard","Multi-Level Wildcard (#)",[14,758,759],{},"Matches any number of levels (must be at the end):",[26,761,762,790,810],{},[29,763,765],{"className":31,"code":764,"filename":33,"language":34,"meta":35,"style":35},"// Subscribe to all user events\nroom.subscribe('users/123/#')\n// Matches: users/123/notifications, users/123/orders/new, users/123\n",[37,766,767,772,785],{"__ignoreMap":35},[40,768,769],{"class":42,"line":43},[40,770,771],{"class":155},"// Subscribe to all user events\n",[40,773,774,776,778,780,783],{"class":42,"line":61},[40,775,162],{"class":50},[40,777,165],{"class":81},[40,779,85],{"class":50},[40,781,782],{"class":57},"'users/123/#'",[40,784,91],{"class":50},[40,786,787],{"class":42,"line":68},[40,788,789],{"class":155},"// Matches: users/123/notifications, users/123/orders/new, users/123\n",[29,791,793],{"className":344,"code":792,"filename":346,"language":347,"meta":35,"style":35},"# Subscribe to all user events\nawait room.subscribe('users/123/#')\n# Matches: users/123/notifications, users/123/orders/new, users/123\n",[37,794,795,800,805],{"__ignoreMap":35},[40,796,797],{"class":42,"line":43},[40,798,799],{},"# Subscribe to all user events\n",[40,801,802],{"class":42,"line":61},[40,803,804],{},"await room.subscribe('users/123/#')\n",[40,806,807],{"class":42,"line":68},[40,808,809],{},"# Matches: users/123/notifications, users/123/orders/new, users/123\n",[29,811,813],{"className":455,"code":812,"filename":457,"language":458,"meta":35,"style":35},"// Subscribe to all user events with handler\nroom.Subscribe(\"users/123/#\", func(data any, meta nolag.MessageMeta) {\n    fmt.Println(\"User event:\", data)\n})\n// Matches: users/123/notifications, users/123/orders/new, users/123\n",[37,814,815,820,825,830,834],{"__ignoreMap":35},[40,816,817],{"class":42,"line":43},[40,818,819],{},"// Subscribe to all user events with handler\n",[40,821,822],{"class":42,"line":61},[40,823,824],{},"room.Subscribe(\"users/123/#\", func(data any, meta nolag.MessageMeta) {\n",[40,826,827],{"class":42,"line":68},[40,828,829],{},"    fmt.Println(\"User event:\", data)\n",[40,831,832],{"class":42,"line":94},[40,833,289],{},[40,835,836],{"class":42,"line":109},[40,837,789],{},[18,839,841],{"id":840},"message-structure","Message Structure",[14,843,844],{},"Messages can contain any JSON-serializable data:",[26,846,847,959,1033],{},[29,848,850],{"className":31,"code":849,"filename":33,"language":34,"meta":35,"style":35},"// Publish structured message\nroom.emit('chat', {\n  type: 'chat_message',\n  sender: {\n    id: 'user-123',\n    name: 'Alice'\n  },\n  content: 'Hello, World!',\n  timestamp: Date.now(),\n  metadata: {\n    room: 'general',\n    thread: null\n  }\n})\n",[37,851,852,857,870,879,884,894,902,907,917,928,933,942,950,955],{"__ignoreMap":35},[40,853,854],{"class":42,"line":43},[40,855,856],{"class":155},"// Publish structured message\n",[40,858,859,861,863,865,868],{"class":42,"line":61},[40,860,162],{"class":50},[40,862,308],{"class":81},[40,864,85],{"class":50},[40,866,867],{"class":57},"'chat'",[40,869,315],{"class":50},[40,871,872,874,877],{"class":42,"line":68},[40,873,321],{"class":50},[40,875,876],{"class":57},"'chat_message'",[40,878,327],{"class":50},[40,880,881],{"class":42,"line":94},[40,882,883],{"class":50},"  sender: {\n",[40,885,886,889,892],{"class":42,"line":109},[40,887,888],{"class":50},"    id: ",[40,890,891],{"class":57},"'user-123'",[40,893,327],{"class":50},[40,895,896,899],{"class":42,"line":114},[40,897,898],{"class":50},"    name: ",[40,900,901],{"class":57},"'Alice'\n",[40,903,904],{"class":42,"line":147},[40,905,906],{"class":50},"  },\n",[40,908,909,912,915],{"class":42,"line":152},[40,910,911],{"class":50},"  content: ",[40,913,914],{"class":57},"'Hello, World!'",[40,916,327],{"class":50},[40,918,919,922,925],{"class":42,"line":159},[40,920,921],{"class":50},"  timestamp: Date.",[40,923,924],{"class":81},"now",[40,926,927],{"class":50},"(),\n",[40,929,930],{"class":42,"line":175},[40,931,932],{"class":50},"  metadata: {\n",[40,934,935,938,940],{"class":42,"line":180},[40,936,937],{"class":50},"    room: ",[40,939,142],{"class":57},[40,941,327],{"class":50},[40,943,944,947],{"class":42,"line":186},[40,945,946],{"class":50},"    thread: ",[40,948,949],{"class":74},"null\n",[40,951,952],{"class":42,"line":220},[40,953,954],{"class":50},"  }\n",[40,956,957],{"class":42,"line":237},[40,958,289],{"class":50},[29,960,962],{"className":344,"code":961,"filename":346,"language":347,"meta":35,"style":35},"# Publish structured message\nawait room.emit('chat', {\n    'type': 'chat_message',\n    'sender': {\n        'id': 'user-123',\n        'name': 'Alice'\n    },\n    'content': 'Hello, World!',\n    'timestamp': time.time(),\n    'metadata': {\n        'room': 'general',\n        'thread': None\n    }\n})\n",[37,963,964,969,974,979,984,989,994,999,1004,1009,1014,1019,1024,1029],{"__ignoreMap":35},[40,965,966],{"class":42,"line":43},[40,967,968],{},"# Publish structured message\n",[40,970,971],{"class":42,"line":61},[40,972,973],{},"await room.emit('chat', {\n",[40,975,976],{"class":42,"line":68},[40,977,978],{},"    'type': 'chat_message',\n",[40,980,981],{"class":42,"line":94},[40,982,983],{},"    'sender': {\n",[40,985,986],{"class":42,"line":109},[40,987,988],{},"        'id': 'user-123',\n",[40,990,991],{"class":42,"line":114},[40,992,993],{},"        'name': 'Alice'\n",[40,995,996],{"class":42,"line":147},[40,997,998],{},"    },\n",[40,1000,1001],{"class":42,"line":152},[40,1002,1003],{},"    'content': 'Hello, World!',\n",[40,1005,1006],{"class":42,"line":159},[40,1007,1008],{},"    'timestamp': time.time(),\n",[40,1010,1011],{"class":42,"line":175},[40,1012,1013],{},"    'metadata': {\n",[40,1015,1016],{"class":42,"line":180},[40,1017,1018],{},"        'room': 'general',\n",[40,1020,1021],{"class":42,"line":186},[40,1022,1023],{},"        'thread': None\n",[40,1025,1026],{"class":42,"line":220},[40,1027,1028],{},"    }\n",[40,1030,1031],{"class":42,"line":237},[40,1032,289],{},[29,1034,1036],{"className":455,"code":1035,"filename":457,"language":458,"meta":35,"style":35},"// Publish structured message\nroom.Emit(\"chat\", map[string]any{\n    \"type\": \"chat_message\",\n    \"sender\": map[string]string{\n        \"id\":   \"user-123\",\n        \"name\": \"Alice\",\n    },\n    \"content\":   \"Hello, World!\",\n    \"timestamp\": time.Now().Unix(),\n    \"metadata\": map[string]any{\n        \"room\":   \"general\",\n        \"thread\": nil,\n    },\n})\n",[37,1037,1038,1042,1047,1052,1057,1062,1067,1071,1076,1081,1086,1091,1096,1100],{"__ignoreMap":35},[40,1039,1040],{"class":42,"line":43},[40,1041,856],{},[40,1043,1044],{"class":42,"line":61},[40,1045,1046],{},"room.Emit(\"chat\", map[string]any{\n",[40,1048,1049],{"class":42,"line":68},[40,1050,1051],{},"    \"type\": \"chat_message\",\n",[40,1053,1054],{"class":42,"line":94},[40,1055,1056],{},"    \"sender\": map[string]string{\n",[40,1058,1059],{"class":42,"line":109},[40,1060,1061],{},"        \"id\":   \"user-123\",\n",[40,1063,1064],{"class":42,"line":114},[40,1065,1066],{},"        \"name\": \"Alice\",\n",[40,1068,1069],{"class":42,"line":147},[40,1070,998],{},[40,1072,1073],{"class":42,"line":152},[40,1074,1075],{},"    \"content\":   \"Hello, World!\",\n",[40,1077,1078],{"class":42,"line":159},[40,1079,1080],{},"    \"timestamp\": time.Now().Unix(),\n",[40,1082,1083],{"class":42,"line":175},[40,1084,1085],{},"    \"metadata\": map[string]any{\n",[40,1087,1088],{"class":42,"line":180},[40,1089,1090],{},"        \"room\":   \"general\",\n",[40,1092,1093],{"class":42,"line":186},[40,1094,1095],{},"        \"thread\": nil,\n",[40,1097,1098],{"class":42,"line":220},[40,1099,998],{},[40,1101,1102],{"class":42,"line":237},[40,1103,289],{},[18,1105,1107],{"id":1106},"message-events","Message Events",[14,1109,1110,1111,1113,1114,1116],{},"Subscribe to various events on a topic. Message handlers receive two arguments: the message ",[37,1112,202],{}," and a ",[37,1115,208],{}," object containing:",[594,1118,1119,1125,1131],{},[597,1120,1121,1124],{},[37,1122,1123],{},"isReplay"," - Whether the message is being replayed from history",[597,1126,1127,1130],{},[37,1128,1129],{},"msgId"," - Unique message ID (for acknowledgement)",[597,1132,1133,1136],{},[37,1134,1135],{},"filter"," - The filter value the message was published with (if any)",[26,1138,1139,1308,1398],{},[29,1140,1142],{"className":31,"code":1141,"filename":33,"language":34,"meta":35,"style":35},"// Subscribe and handle events\nroom.subscribe('chat')\n\n// Incoming messages (includes meta with isReplay, msgId, filter)\nroom.on('chat', (data, meta) => {\n  console.log('Data:', data, 'Meta:', meta)\n})\n\n// Connection events\nclient.on('connect', () => {\n  console.log('Successfully connected')\n})\n\nclient.on('error', (err) => {\n  console.error('Connection error:', err)\n})\n",[37,1143,1144,1149,1161,1165,1170,1194,1214,1218,1222,1227,1246,1259,1263,1267,1289,1304],{"__ignoreMap":35},[40,1145,1146],{"class":42,"line":43},[40,1147,1148],{"class":155},"// Subscribe and handle events\n",[40,1150,1151,1153,1155,1157,1159],{"class":42,"line":61},[40,1152,162],{"class":50},[40,1154,165],{"class":81},[40,1156,85],{"class":50},[40,1158,867],{"class":57},[40,1160,91],{"class":50},[40,1162,1163],{"class":42,"line":68},[40,1164,65],{"emptyLinePlaceholder":64},[40,1166,1167],{"class":42,"line":94},[40,1168,1169],{"class":155},"// Incoming messages (includes meta with isReplay, msgId, filter)\n",[40,1171,1172,1174,1176,1178,1180,1182,1184,1186,1188,1190,1192],{"class":42,"line":109},[40,1173,162],{"class":50},[40,1175,191],{"class":81},[40,1177,85],{"class":50},[40,1179,867],{"class":57},[40,1181,198],{"class":50},[40,1183,202],{"class":201},[40,1185,205],{"class":50},[40,1187,208],{"class":201},[40,1189,211],{"class":50},[40,1191,214],{"class":46},[40,1193,217],{"class":50},[40,1195,1196,1198,1200,1202,1205,1208,1211],{"class":42,"line":114},[40,1197,223],{"class":50},[40,1199,226],{"class":81},[40,1201,85],{"class":50},[40,1203,1204],{"class":57},"'Data:'",[40,1206,1207],{"class":50},", data, ",[40,1209,1210],{"class":57},"'Meta:'",[40,1212,1213],{"class":50},", meta)\n",[40,1215,1216],{"class":42,"line":147},[40,1217,289],{"class":50},[40,1219,1220],{"class":42,"line":152},[40,1221,65],{"emptyLinePlaceholder":64},[40,1223,1224],{"class":42,"line":159},[40,1225,1226],{"class":155},"// Connection events\n",[40,1228,1229,1232,1234,1236,1239,1242,1244],{"class":42,"line":175},[40,1230,1231],{"class":50},"client.",[40,1233,191],{"class":81},[40,1235,85],{"class":50},[40,1237,1238],{"class":57},"'connect'",[40,1240,1241],{"class":50},", () ",[40,1243,214],{"class":46},[40,1245,217],{"class":50},[40,1247,1248,1250,1252,1254,1257],{"class":42,"line":180},[40,1249,223],{"class":50},[40,1251,226],{"class":81},[40,1253,85],{"class":50},[40,1255,1256],{"class":57},"'Successfully connected'",[40,1258,91],{"class":50},[40,1260,1261],{"class":42,"line":186},[40,1262,289],{"class":50},[40,1264,1265],{"class":42,"line":220},[40,1266,65],{"emptyLinePlaceholder":64},[40,1268,1269,1271,1273,1275,1278,1280,1283,1285,1287],{"class":42,"line":237},[40,1270,1231],{"class":50},[40,1272,191],{"class":81},[40,1274,85],{"class":50},[40,1276,1277],{"class":57},"'error'",[40,1279,198],{"class":50},[40,1281,1282],{"class":201},"err",[40,1284,211],{"class":50},[40,1286,214],{"class":46},[40,1288,217],{"class":50},[40,1290,1291,1293,1296,1298,1301],{"class":42,"line":252},[40,1292,223],{"class":50},[40,1294,1295],{"class":81},"error",[40,1297,85],{"class":50},[40,1299,1300],{"class":57},"'Connection error:'",[40,1302,1303],{"class":50},", err)\n",[40,1305,1306],{"class":42,"line":267},[40,1307,289],{"class":50},[29,1309,1311],{"className":344,"code":1310,"filename":346,"language":347,"meta":35,"style":35},"# Subscribe and handle events\nawait room.subscribe('chat')\n\n# Incoming messages (includes meta with isReplay, msgId, filter)\ndef handle_message(data, meta):\n    print('Data:', data, 'Meta:', meta)\n\nroom.on('chat', handle_message)\n\n# Connection events\ndef on_connect():\n    print('Successfully connected')\n\ndef on_error(err):\n    print('Connection error:', err)\n\nclient.on('connect', on_connect)\nclient.on('error', on_error)\n",[37,1312,1313,1318,1323,1327,1332,1337,1342,1346,1351,1355,1360,1365,1370,1374,1379,1384,1388,1393],{"__ignoreMap":35},[40,1314,1315],{"class":42,"line":43},[40,1316,1317],{},"# Subscribe and handle events\n",[40,1319,1320],{"class":42,"line":61},[40,1321,1322],{},"await room.subscribe('chat')\n",[40,1324,1325],{"class":42,"line":68},[40,1326,65],{"emptyLinePlaceholder":64},[40,1328,1329],{"class":42,"line":94},[40,1330,1331],{},"# Incoming messages (includes meta with isReplay, msgId, filter)\n",[40,1333,1334],{"class":42,"line":109},[40,1335,1336],{},"def handle_message(data, meta):\n",[40,1338,1339],{"class":42,"line":114},[40,1340,1341],{},"    print('Data:', data, 'Meta:', meta)\n",[40,1343,1344],{"class":42,"line":147},[40,1345,65],{"emptyLinePlaceholder":64},[40,1347,1348],{"class":42,"line":152},[40,1349,1350],{},"room.on('chat', handle_message)\n",[40,1352,1353],{"class":42,"line":159},[40,1354,65],{"emptyLinePlaceholder":64},[40,1356,1357],{"class":42,"line":175},[40,1358,1359],{},"# Connection events\n",[40,1361,1362],{"class":42,"line":180},[40,1363,1364],{},"def on_connect():\n",[40,1366,1367],{"class":42,"line":186},[40,1368,1369],{},"    print('Successfully connected')\n",[40,1371,1372],{"class":42,"line":220},[40,1373,65],{"emptyLinePlaceholder":64},[40,1375,1376],{"class":42,"line":237},[40,1377,1378],{},"def on_error(err):\n",[40,1380,1381],{"class":42,"line":252},[40,1382,1383],{},"    print('Connection error:', err)\n",[40,1385,1386],{"class":42,"line":267},[40,1387,65],{"emptyLinePlaceholder":64},[40,1389,1390],{"class":42,"line":286},[40,1391,1392],{},"client.on('connect', on_connect)\n",[40,1394,1395],{"class":42,"line":292},[40,1396,1397],{},"client.on('error', on_error)\n",[29,1399,1401],{"className":455,"code":1400,"filename":457,"language":458,"meta":35,"style":35},"// Subscribe with handler. Messages arrive directly in the callback\nroom.Subscribe(\"chat\", func(data any, meta nolag.MessageMeta) {\n    fmt.Println(\"Data:\", data, \"Meta:\", meta)\n})\n\n// Connection events\nclient.On(\"connected\", func(args ...any) {\n    fmt.Println(\"Successfully connected\")\n})\n\nclient.On(\"error\", func(args ...any) {\n    fmt.Println(\"Connection error:\", args[0])\n})\n",[37,1402,1403,1408,1413,1418,1422,1426,1430,1435,1440,1444,1448,1453,1458],{"__ignoreMap":35},[40,1404,1405],{"class":42,"line":43},[40,1406,1407],{},"// Subscribe with handler. Messages arrive directly in the callback\n",[40,1409,1410],{"class":42,"line":61},[40,1411,1412],{},"room.Subscribe(\"chat\", func(data any, meta nolag.MessageMeta) {\n",[40,1414,1415],{"class":42,"line":68},[40,1416,1417],{},"    fmt.Println(\"Data:\", data, \"Meta:\", meta)\n",[40,1419,1420],{"class":42,"line":94},[40,1421,289],{},[40,1423,1424],{"class":42,"line":109},[40,1425,65],{"emptyLinePlaceholder":64},[40,1427,1428],{"class":42,"line":114},[40,1429,1226],{},[40,1431,1432],{"class":42,"line":147},[40,1433,1434],{},"client.On(\"connected\", func(args ...any) {\n",[40,1436,1437],{"class":42,"line":152},[40,1438,1439],{},"    fmt.Println(\"Successfully connected\")\n",[40,1441,1442],{"class":42,"line":159},[40,1443,289],{},[40,1445,1446],{"class":42,"line":175},[40,1447,65],{"emptyLinePlaceholder":64},[40,1449,1450],{"class":42,"line":180},[40,1451,1452],{},"client.On(\"error\", func(args ...any) {\n",[40,1454,1455],{"class":42,"line":186},[40,1456,1457],{},"    fmt.Println(\"Connection error:\", args[0])\n",[40,1459,1460],{"class":42,"line":220},[40,1461,289],{},[18,1463,1465],{"id":1464},"unsubscribing","Unsubscribing",[14,1467,1468],{},"Unsubscribe when you no longer need to receive messages:",[26,1470,1471,1512,1541],{},[29,1472,1474],{"className":31,"code":1473,"filename":33,"language":34,"meta":35,"style":35},"// Unsubscribe from a topic\nroom.unsubscribe('chat')\n\n// Disconnect client (synchronous, no await needed)\nclient.disconnect()\n",[37,1475,1476,1481,1494,1498,1503],{"__ignoreMap":35},[40,1477,1478],{"class":42,"line":43},[40,1479,1480],{"class":155},"// Unsubscribe from a topic\n",[40,1482,1483,1485,1488,1490,1492],{"class":42,"line":61},[40,1484,162],{"class":50},[40,1486,1487],{"class":81},"unsubscribe",[40,1489,85],{"class":50},[40,1491,867],{"class":57},[40,1493,91],{"class":50},[40,1495,1496],{"class":42,"line":68},[40,1497,65],{"emptyLinePlaceholder":64},[40,1499,1500],{"class":42,"line":94},[40,1501,1502],{"class":155},"// Disconnect client (synchronous, no await needed)\n",[40,1504,1505,1507,1510],{"class":42,"line":109},[40,1506,1231],{"class":50},[40,1508,1509],{"class":81},"disconnect",[40,1511,106],{"class":50},[29,1513,1515],{"className":344,"code":1514,"filename":346,"language":347,"meta":35,"style":35},"# Unsubscribe from a topic\nawait room.unsubscribe('chat')\n\n# Disconnect client (synchronous)\nclient.disconnect()\n",[37,1516,1517,1522,1527,1531,1536],{"__ignoreMap":35},[40,1518,1519],{"class":42,"line":43},[40,1520,1521],{},"# Unsubscribe from a topic\n",[40,1523,1524],{"class":42,"line":61},[40,1525,1526],{},"await room.unsubscribe('chat')\n",[40,1528,1529],{"class":42,"line":68},[40,1530,65],{"emptyLinePlaceholder":64},[40,1532,1533],{"class":42,"line":94},[40,1534,1535],{},"# Disconnect client (synchronous)\n",[40,1537,1538],{"class":42,"line":109},[40,1539,1540],{},"client.disconnect()\n",[29,1542,1544],{"className":455,"code":1543,"filename":457,"language":458,"meta":35,"style":35},"// Unsubscribe from a topic\nroom.Unsubscribe(\"chat\")\n\n// Disconnect client\nclient.Close()\n",[37,1545,1546,1550,1555,1559,1564],{"__ignoreMap":35},[40,1547,1548],{"class":42,"line":43},[40,1549,1480],{},[40,1551,1552],{"class":42,"line":61},[40,1553,1554],{},"room.Unsubscribe(\"chat\")\n",[40,1556,1557],{"class":42,"line":68},[40,1558,65],{"emptyLinePlaceholder":64},[40,1560,1561],{"class":42,"line":94},[40,1562,1563],{},"// Disconnect client\n",[40,1565,1566],{"class":42,"line":109},[40,1567,1568],{},"client.Close()\n",[18,1570,1572],{"id":1571},"next-steps","Next Steps",[594,1574,1575,1583,1589,1595],{},[597,1576,1577,1582],{},[1578,1579,1581],"a",{"href":1580},"/docs/concepts/filters","Topic Filters"," - narrow delivery to specific entities within a topic",[597,1584,1585],{},[1578,1586,1588],{"href":1587},"/docs/concepts/rooms","Learn about Rooms",[597,1590,1591],{},[1578,1592,1594],{"href":1593},"/docs/concepts/qos","Configure Quality of Service",[597,1596,1597],{},[1578,1598,1600],{"href":1599},"/docs/concepts/acl","Set up Access Control",[1602,1603,1604],"style",{},"html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":35,"searchDepth":61,"depth":61,"links":1606},[1607,1608,1611,1615,1616,1617,1618],{"id":20,"depth":61,"text":21},{"id":588,"depth":61,"text":589,"children":1609},[1610],{"id":624,"depth":68,"text":625},{"id":649,"depth":61,"text":650,"children":1612},[1613,1614],{"id":656,"depth":68,"text":657},{"id":755,"depth":68,"text":756},{"id":840,"depth":61,"text":841},{"id":1106,"depth":61,"text":1107},{"id":1464,"depth":61,"text":1465},{"id":1571,"depth":61,"text":1572},"Learn about NoLag topics and the pub/sub messaging model. Understand topic patterns, wildcards, and message routing.","md",{},"/docs/concepts/topics",{"title":5,"description":1619},"docs/concepts/topics","Ch_MQ-V5kW0aRh0dlNEMhsNhqXQSTck8_xTaNFsQcG8",1788160343201]