### Start AMPS Server Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/quick_start/index.html Navigate to the AMPS distribution directory and start the AMPS server using the sample configuration file. ```bash $ cd ~/amps_dir/ $ ./bin/ampServer ./config/server-config.xml ``` -------------------------------- ### Install AMPS NPM Package Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/quick_start/index.html Install the AMPS JavaScript client library in your project's quickstart samples directory using NPM. Node.js v7.11 or higher is required. ```bash cd amps-client-javascript/quickstart/samples npm install --save amps ``` -------------------------------- ### Start AMPS Server with Configuration Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/quick_start/chapters/quickstart.html Navigate to the AMPS distribution directory and start the AMPS server using the provided configuration file. Ensure you are in the correct directory before running this command. ```bash cd ~/amps_dir/ ./bin/ampServer ./config/server-config.xml ``` -------------------------------- ### getStart() Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/bookmarkrangefield.html Retrieves the start bookmark of the range. ```APIDOC ## getStart * getStart(): BookmarkField * This method returns the start bookmark of a range. #### Returns BookmarkField The start bookmark field of a range. ``` -------------------------------- ### replaceStart(start, makeExclusive) Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/bookmarkrangefield.html Replaces the start bookmark of the range with a new value. ```APIDOC ## replaceStart * replaceStart(start: BookmarkField, makeExclusive?: boolean): void * This method replaces the start bookmark of the range. #### Parameters * ##### start: BookmarkField The bookmark field object with the new start value. * ##### Default value makeExclusive: boolean = true If true, the new start range should be exclusive, otherwise it keeps the previous value. #### Returns void ``` -------------------------------- ### TypeScript Reference for Manual Installation Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/developer_guide/chapters/first-program.html When manually installing the AMPS client in a TypeScript project, reference the typing file to ensure proper type checking and autocompletion. ```typescript /// import { Client, Command } from './lib/amps'; ``` -------------------------------- ### Initialize MemoryBookmarkStore and Assign to Client Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/memorybookmarkstore.html Demonstrates how to create an instance of MemoryBookmarkStore and associate it with an AMPS Client. This setup is necessary for enabling bookmarking features. ```javascript var bookmarkStore = new amps.MemoryBookmarkStore(); var client = new amps.Client('my-client'); client.bookmarkStore(bookmarkStore); // ... access the bookmark store later client.bookmarkStore().purge(); ``` -------------------------------- ### Install AMPS JavaScript Client using NPM Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/index.html Install the AMPS JavaScript client library using NPM. This command adds the 'amps' package as a dependency to your project. ```bash npm install --save amps ``` -------------------------------- ### options Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/command.html Sets or gets the comma-delimited string of options for a command. ```APIDOC ## options * options(value: string): Command * options(): string * Sets the (comma-delimited) string of options on a specific Command. #### Parameters * ##### value: string The options (comma-delimited) string value. #### Returns Command The updated Command object. * * * * Returns the options (comma-delimited) string value. #### Returns string The options (comma-delimited) string value. ``` -------------------------------- ### Connect and Subscribe to a Topic Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/index.html Connect to an AMPS server and subscribe to a topic to receive messages. This example demonstrates asynchronous connection, subscription, and publishing. ```javascript import { Client } from 'amps'; (async () => { const client = new Client('my-application'); try { await client.connect('ws://localhost:9100/amps/json'); // Connected, let's subscribe to a topic now const subscriptionId = await client.subscribe( message => console.log(message.data), 'orders' ); // Once we subscribed, the subscriptionId is returned console.log(subscriptionId); client.publish('orders', {order: 'Tesla 3', qty: 10}); } catch (err) { // This can be either a connection error or a subscription error console.log(err); } })(); ``` -------------------------------- ### command Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/command.html Sets or gets the command to be executed (e.g., 'publish', 'subscribe'). ```APIDOC ## command * command(value: string): Command * command(): string * Sets the command e.g. 'publish', 'sow_and_subscribe', to be executed. The following commands are available: * publish * delta_publish * subscribe * delta_subscribe * sow * sow_and_subscribe * sow_and_delta_subscribe * sow_delete * unsubscribe #### Parameters * ##### value: string The command name value. #### Returns Command The updated Command object. * * * * Returns the Command name. #### Returns string The Command name value. ``` -------------------------------- ### Execute sow_and_subscribe Command with Client.execute() Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/developer_guide/chapters/sow.html Use `Client.execute()` with a `Command` object for 'sow_and_subscribe' to get initial state and real-time updates. This method allows for more explicit command construction and configuration. Handles 'sow', 'p', and 'oof' messages. ```javascript // Message Handler const onVanPositionUpdate = message => { const cmdName = message.header.command(); if (cmdName === 'sow' || cmdName === 'p') { addOrUpdateVan(message); } else if (cmdName === 'oof') { removeVan(message); } }; const reportVanPosition = async client => { // Command object to execute const cmd = new Command('sow_and_subscribe'); cmd.topic('van_location'); cmd.filter('/status = "ACTIVE"'); cmd.batchSize(100); cmd.options('oof'); // Execute the command with the above message handler return client.execute(cmd, onVanPositionUpdate); }; ``` -------------------------------- ### Example WebSocket Connection String Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/developer_guide/chapters/first-program.html A basic connection string for a JavaScript client connecting to a local AMPS instance using WebSocket. ```plaintext ws://localhost:9007/amps/json ``` -------------------------------- ### Bookmark Subscription With Content Filter Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/developer_guide/chapters/creating-commands.html Use this command to create a bookmark subscription with an optional content filter. Set the 'Bookmark' property to specify the starting point and 'Filter' to include only matching messages. ```text Topic Sets the topic to subscribe to. The topic provided can be either the exact name of the topic, or a regular expression that matches the names of the topics for the subscription. `Bookmark` Sets the point in the transaction log at which the subscription will begin. The bookmark provided can be a specific AMPS bookmark, a timestamp, or one of the client-provided constants. AMPS also accepts a comma-delimited list of bookmarks. In this case, AMPS begins the subscription from whichever of the bookmarks is earliest in the transaction log. `Filter` Sets the content filter to be applied to the subscription. Only messages that match the content filter will be provided to the subscription. ``` -------------------------------- ### logonOptions Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/client.html Sets or gets the logon options for the client. These options can also be provided during the `connect()` method call and cannot be changed after the client is connected. ```APIDOC ## logonOptions ### Description Sets or gets the logon options of the client. Logon options can also be set via the connect() method as an optional argument. Logon options can't be set after the client is connected and logged on. ### Method Signature `logonOptions(): string` `logonOptions(logonOptions: string): Client` ### Parameters #### Path Parameters - **logonOptions** (string) - Optional - The logon options string. ### Returns - `string` - The logon options if called as a getter. - `Client` - The client object if called as a setter. ### Example ```javascript // create a client and set the logon options const client = new Client().logonOptions('pretty,ack_conflation=300ms'); // ... access the logon options later console.log(client.logonOptions()); ``` ``` -------------------------------- ### Import AMPS Client and Command in TypeScript (Manual) Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/index.html Import AMPS modules in a TypeScript project after manual installation. Ensure to include a typing reference for the client library. ```typescript // Manual installation (don't forget to add a typing reference): /// import * as amps from './amps'; import { Client, Command } from './amps'; ``` -------------------------------- ### Use AMPS Client with AMD Modules Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/index.html Load and use the AMPS client library within an application that utilizes AMD modules. This example shows how to define and consume the 'amps' module. ```javascript define(['dist/amps'], amps => { console.log(amps.Client.version()); }); ``` -------------------------------- ### AMPS Configuration for WebSocket Transport Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/developer_guide/chapters/first-program.html Example AMPS configuration snippet showing how to set up a WebSocket protocol and transport, which is required for the JavaScript client. ```xml ... ... websocket-any websocket ... ... websocket-any tcp 9007 websocket-any ... ``` -------------------------------- ### Publish a Message to a Topic Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/index.html Connect to an AMPS server and publish a message to a specified topic. This example demonstrates a simple publish operation without requiring prior topic configuration. ```javascript // ... in asynchronous context try { const client = new Client('publish-example'); await client.connect('ws://localhost:9100/amps/xml'); client.publish('messages', 'Hello, world!'); } catch (err) { console.log(err); } ``` -------------------------------- ### Set and Get Logon Options Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/client.html Configures or retrieves logon options for the client connection. These options can also be set during the connect() method. Note that logon options cannot be modified after the client has connected and logged on. ```javascript const client = new Client().logonOptions('pretty,ack_conflation=300ms'); // ... access the logon options later console.log(client.logonOptions()); ``` -------------------------------- ### Run Sample Publisher Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/quick_start/chapters/quickstart.html Execute the AMPSConsolePublisher.js sample and run it in the background. This will send a 'Hello, World' message to subscribers. ```bash $ node AMPSConsolePublisher.js & ``` -------------------------------- ### Get AMPS Client Version in Node.js Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/index.html Retrieve the version of the AMPS client library in a Node.js environment. This is a basic check after installation. ```javascript const { Client } = require('amps'); console.log(Client.version()); ``` -------------------------------- ### Initialize and Use DefaultSubscriptionManager Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/defaultsubscriptionmanager.html Demonstrates how to create a client, assign a DefaultSubscriptionManager to it, and access its methods later. Ensure the client is initialized before managing subscriptions. ```javascript const client = new Client('my-client'); client.subscriptionManager(new DefaultSubscriptionManager()); client.subscriptionManager().clear(); ``` -------------------------------- ### Create and Configure DefaultServerChooser Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/developer_guide/chapters/high-availability.html Instantiate a Client and DefaultServerChooser, add server URIs, and assign the chooser to the client. Use this for basic testing or simple server rotation. ```javascript const memoryClient = new Client('server-chooser-demo'); // primary.amps.xyz.com is the primary AMPS instance, // and // secondary.amps.xyz.com is the secondary const chooser = new DefaultServerChooser(); chooser.add('ws://primary.amps.xyz.com:12345/amps/fix'); chooser.add('ws://secondary.amps.xyz.com:12345/amps/fix'); memoryClient.serverChooser(chooser); try { await memoryClient.connect(); // ... later await client.disconnect(); } catch (err) { // handle connection error } ``` -------------------------------- ### Create ExponentialDelayStrategy with All Arguments Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/exponentialdelaystrategy.html Initialize the strategy by passing all configuration parameters as individual arguments. ```javascript const strategy = new ExponentialDelayStrategy(400, 25000, 1.5, 0, 2.5); ``` -------------------------------- ### isStartInclusive() Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/bookmarkrangefield.html Checks if the start of the bookmark range is inclusive. ```APIDOC ## isStartInclusive * isStartInclusive(): boolean * This method returns whether the start of the range is inclusive or not. #### Returns boolean True if the start range is inclusive, false otherwise. ``` -------------------------------- ### filter Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/command.html Sets or gets the content filter expression. ```APIDOC ## filter * filter(value: string): Command * filter(): string * Sets the content filter expression. #### Parameters * ##### value: string The filter value. #### Returns Command The updated Command object. * * * * Returns the filter value. #### Returns string The filter value. ``` -------------------------------- ### Run SOW Publisher Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/quick_start/chapters/quickstart.html Execute the AMPSSOWConsolePublisher.js sample to send 100 messages to a State of the World database topic, including an update to message 5. ```bash $ node AMPSSOWConsolePublisher.js & ``` -------------------------------- ### Run Sample Subscriber Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/quick_start/chapters/quickstart.html Execute the AMPSConsoleSubscriber.js sample and run it in the background. Messages will be displayed in the console. ```bash $ node AMPSConsoleSubscriber.js & ``` -------------------------------- ### Create Memory-Backed Client - JavaScript Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/client.html Creates a client instance that stores bookmarks and subscriptions in memory. Ideal for scenarios where persistence is not required or managed externally. ```javascript const client = Client.createMemoryBacked("myClientName"); ``` -------------------------------- ### correlationId Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/command.html Sets or gets an opaque token for correlating messages. ```APIDOC ## correlationId * correlationId(value: string): Command * correlationId(): string * Sets the opaque token set by an application and returned with the message. #### Parameters * ##### value: string The correlationId value. #### Returns Command The updated Command object. * * * * Returns the correlationId value. #### Returns string The correlationId value. ``` -------------------------------- ### Initialize and Connect with DefaultServerChooser Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/defaultserverchooser.html Instantiate DefaultServerChooser, add server URIs, set it on the client, and then connect. This is the primary way to configure server selection for the AMPS client. ```javascript const chooser = new DefaultServerChooser(); chooser.add('wss://server:9005/amps/nvfix'); chooser.add('wss://server-two:9005/amps/nvfix'); const client = new Client('showchooser'); client.serverChooser(chooser); await client.connect(); ``` -------------------------------- ### commandId Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/command.html Sets or gets a client-specified command ID for correlating responses. ```APIDOC ## commandId * commandId(value: string): Command * commandId(): string * Sets the Client-specified command id. The command id is returned by the engine in responses to commands to allow the client to correlate the response to the command. #### Parameters * ##### value: string The command id value. #### Returns Command The updated Command object. * * * * Returns the command id. #### Returns string The command id value. ``` -------------------------------- ### ExponentialDelayStrategy Constructor Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/exponentialdelaystrategy.html Demonstrates how to create an instance of ExponentialDelayStrategy with default values, partial configuration, full configuration via arguments, full configuration via an object, or using setter methods. ```APIDOC ## ExponentialDelayStrategy Constructor ### Description Initializes a new instance of the ExponentialDelayStrategy class. ### Usage **Default values:** ```javascript const strategy = new ExponentialDelayStrategy(); ``` **With specific parameters:** ```javascript // Using an options object const strategy = new ExponentialDelayStrategy({jitter: 3.5}); // Using arguments const strategy = new ExponentialDelayStrategy(400, 25000, 1.5, 0, 2.5); // Using an object with named properties const strategy = new ExponentialDelayStrategy({ initialDelay: 400, maximumDelay: 25000, backoffExponent: 1.5, maximumRetryTime: 0, jitter: 2.5 }); // Using setter methods const strategy = new ExponentialDelayStrategy() .initialDelay(400) .maximumDelay(25000) .backoffExponent(1.5) .maximumRetryTime(0) .jitter(2.5); ``` ### Parameters (for object initialization) - **initialDelay** (number) - Optional - The initial delay in milliseconds. - **maximumDelay** (number) - Optional - The maximum delay in milliseconds. - **backoffExponent** (number) - Optional - The exponent used for calculating backoff. - **maximumRetryTime** (number) - Optional - The maximum time in milliseconds to retry before giving up. - **jitter** (number) - Optional - The jitter to apply to the delay. ### Methods Setter methods like `initialDelay()`, `maximumDelay()`, `backoffExponent()`, `maximumRetryTime()`, and `jitter()` can be chained after initialization or used to dynamically change values. ``` -------------------------------- ### Create ExponentialDelayStrategy with Setter Methods Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/exponentialdelaystrategy.html Initialize the strategy and then use setter methods to configure each parameter. ```javascript const strategy = new ExponentialDelayStrategy() .initialDelay(400) .maximumDelay(25000) .backoffExponent(1.5) .maximumRetryTime(0) .jitter(2.5); ``` -------------------------------- ### disconnectHandler Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/client.html Sets or gets the disconnect handler, which is invoked in case of an unintentional disconnection. ```APIDOC ## disconnectHandler ### Description Sets or gets the disconnect handler that is invoked in case of an unintentional disconnection. ### Method `disconnectHandler(): function` `disconnectHandler(disconnectHandler: function): Client` ### Parameters #### Setter * **disconnectHandler** (function) - A function with the signature `(client: Client, error: Error): void` that will be called when the client unintentionally disconnects. ### Returns * `function` - The disconnect handler if called as a getter. * `Client` - The client instance if called as a setter. ### Example ```javascript const disconnectHandler = (client, err) => { // when the Client unintentionally disconnects, this method is invoked. console.error('err: ', err); }; const client = new Client().disconnectHandler(disconnectHandler); ``` ``` -------------------------------- ### Constructor Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/bookmarkrangefield.html Initializes a new instance of the BookmarkRangeField class. ```APIDOC ## constructor * new BookmarkRangeField(rawBookmark?: string): BookmarkRangeField * #### Parameters * ##### Default value rawBookmark: string = null The string of a range format, for example: `[20190808T100002Z:20190808T100004Z]`. #### Returns BookmarkRangeField ``` -------------------------------- ### expiration Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/command.html Sets or gets the SOW expiration time in seconds for 'publish' commands. ```APIDOC ## expiration * expiration(value: number): Command * expiration(): number * Sets the SOW expiration time (in seconds) if used in `publish`. #### Parameters * ##### value: number The command expiration value (in seconds). #### Returns Command The updated Command object. * * * * Returns the command expiration value (in seconds). #### Returns number The command expiration value. ``` -------------------------------- ### bookmark Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/command.html Sets or gets a client-originated identifier to mark a location in journaled messages. ```APIDOC ## bookmark * bookmark(value: string): Command * bookmark(): string * Sets the client-originated identifier used to mark a location in journaled messages. #### Parameters * ##### value: string The bookmark value. #### Returns Command The updated Command object. * * * * Returns the bookmark value. #### Returns string The bookmark value. ``` -------------------------------- ### Copy Server Configuration File Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/quick_start/index.html Copy the sample server configuration file into your AMPS config directory. ```bash $ cp ~/amps-client-javascript/quickstart/server-config.xml ~/amps_dir/config/server-config.xml ``` -------------------------------- ### Create AMPS Client with Memory Stores Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/developer_guide/chapters/high-availability.html Creates a client with memory-backed bookmark and publish stores for full HA protection. This offers the highest performance but no protection against client application crashes. ```javascript // Failover, Bookmark and Publish stores, re-subscription const memoryClient = Client.createMemoryBacked('memory-backed'); ``` -------------------------------- ### batchSize Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/command.html Sets or gets the batch size for query results. Defaults to 10. ```APIDOC ## batchSize * batchSize(value: number): Command * batchSize(): number * Sets the number of messages that are batched together when returning a query result. If it's not set, it is `10` by default. #### Parameters * ##### value: number The batch size value. #### Returns Command The updated Command object. * * * * Returns the batch size value. #### Returns number The batch size value. ``` -------------------------------- ### DefaultServerChooser Constructor Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/defaultserverchooser.html Initializes a new instance of the DefaultServerChooser. ```APIDOC ## constructor ### Description This is the constructor for the DefaultServerChooser class. ### Returns DefaultServerChooser - The newly created DefaultServerChooser instance. ``` -------------------------------- ### failedWriteHandler Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/client.html Sets or gets the failed write handler for reporting failed publishes to AMPS. ```APIDOC ## failedWriteHandler ### Description Sets or gets the failed write handler for reporting failed publishes to AMPS, for example, due to insufficient entitlements. ### Method `failedWriteHandler(): function` `failedWriteHandler(failedWriteHandler: function): Client` ### Parameters #### Setter * **failedWriteHandler** (function) - A function with the signature `(message: Message, reason: string): void` that will be called when a write operation fails. ### Returns * `function` - The failed write handler if called as a getter. * `Client` - The client instance if called as a setter. ### Example ```javascript const client = new Client().failedWriteHandler((message, reason) => { console.log('Failed to publish -- reason:', reason); console.log('Failed to publish -- message data: ', message.data); }); ``` ``` -------------------------------- ### errorHandler Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/client.html Sets or gets the error handler for general errors such as connection issues or exceptions. ```APIDOC ## errorHandler ### Description Sets or gets the error handler for all general errors such as connection issues, exceptions, etc. ### Method `errorHandler(): function` `errorHandler(errorHandler: function): Client` ### Parameters #### Setter * **errorHandler** (function) - A function with the signature `(error: Error): void` that will be called when a general error occurs. ### Returns * `function` - The error handler if called as a getter. * `Client` - The client instance if called as a setter. ### Example ```javascript const client = new Client().errorHandler(err => console.error('err: ', err)); ``` ``` -------------------------------- ### Client.connect() Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference?_gl=1%2A1svuue0%2A_ga%2ANTg1ODk3MjUzLjE3ODI3Mjc0NTU.%2A_ga_BECZTGT2L7%2AczE3ODI3NTA4NDAkbzIkZzEkdDE3ODI3NTA5NjUkajYwJGwwJGgwJGRfUHZnUUl4U2ZnTFZMc3d3QXgxUnZ6YjJHanl2bXVYVXN3 Establishes a connection to the AMPS server. ```APIDOC ## client.connect(url) ### Description Connects the client to an AMPS server at the specified WebSocket URL. ### Method `client.connect(url)` ### Parameters #### Path Parameters - **url** (string) - Required - The WebSocket URL of the AMPS server (e.g., 'ws://localhost:9100/amps/json'). ### Example ```javascript const client = new Client('my-application'); await client.connect('ws://localhost:9100/amps/json'); ``` ``` -------------------------------- ### ackType Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/command.html Sets or gets the acknowledgement types for the command. Multiple ack types should be comma-delimited. ```APIDOC ## ackType * ackType(value: string): Command * ackType(): string * Sets the acknowledgements requested for the command. Multiple ack types should be comma-delimited. The acknowledgement messages will be delivered to the message handler. #### Parameters * ##### value: string The acknowledgement message type(s). #### Returns Command The updated Command object. * * * * Returns the acknowledgement message type(s). #### Returns string The acknowledgement message type(s). ``` -------------------------------- ### Get AMPS Client Version - JavaScript Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/client.html Retrieves the version string of the AMPS client library. ```javascript const version = Client.version(); console.log(`AMPS Client Version: ${version}`); ``` -------------------------------- ### Create ExponentialDelayStrategy with Object of Values Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/exponentialdelaystrategy.html Initialize the strategy by providing an object containing all configuration parameters. ```javascript const strategy = new ExponentialDelayStrategy({ initialDelay: 400, maximumDelay: 25000, backoffExponent: 1.5, maximumRetryTime: 0, jitter: 2.5 }); ``` -------------------------------- ### data Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/command.html Sets or gets the command data (message payload). Applicable for 'publish', 'delta_publish', and 'sow_delete' commands. ```APIDOC ## data * data(value: any): Command * data(): any * Sets the command data (message payload). Makes sense only for `publish`, `delta_publish`, and `sow_delete` commands. #### Parameters * ##### value: any The Command data (message payload). #### Returns Command The updated Command object. * * * * Returns the Command data (message payload). #### Returns any The Command data (message payload). ``` -------------------------------- ### Run SOW Subscriber with Updates Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/quick_start/chapters/quickstart.html Execute the AMPSSOWandSubscribeConsoleSubscriber.js sample to query the State of the World and subscribe to subsequent updates for messages matching the filter. ```bash $ node AMPSSOWandSubscribeConsoleSubscriber.js & ``` -------------------------------- ### delimiter Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/fixtypehelper.html Allows setting or getting the delimiter value for the helper. The delimiter is used to parse FIX/NVFIX messages. ```APIDOC ## delimiter(delimiter: string): FixTypeHelper ### Description Sets the delimiter value for the helper. ### Parameters #### delimiter: string The new delimiter value. ### Returns FixTypeHelper The helper object. --- ## delimiter(): string ### Description Returns the delimiter value of the helper. ### Returns string The delimiter value. ``` -------------------------------- ### Get Server Version Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/client.html Retrieve the AMPS server version as a string. Returns null if the client has not yet logged on. ```javascript client.serverVersion(); ``` -------------------------------- ### Subscribe to a Topic using Command Interface Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/developer_guide/chapters/subscriptions.html Use the Command interface for precise control over subscription parameters. This is recommended for flexibility and maintenance. The execute() method resolves with the subscription ID. ```javascript /** * Let's create a message handler function. It will be invoked * when AMPS delivers messages to the subscription. * Within this handler, we process messages. In this case, * we simply print the contents of the message. */ const onMessage = message => console.log(message.data); // let's create a Client that is connected to an AMPS server. const client = new Client('test'); await client.connect('wss://127.0.0.1:9007/amps/json'); /** * Here we create a Command object for the subscribe * command, specifying the topic "messages". We do not * provide a filter, so AMPS does not content-filter * the topic. */ const cmd = new Command('subscribe').topic('messages'); /** * We execute the Command using the execute() method. * The command execution resolves with the id of the * subscription. */ const subId = await client.execute(cmd, onMessage); console.log('subId: ', subId); ``` -------------------------------- ### Get AMPS Client Version (TypeScript - Import All) Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/?_gl=1*1svuue0*_ga*NTg1ODk3MjUzLjE3ODI3Mjc0NTU.*_ga_BECZTGT2L7*czE3ODI3NTA4NDAkbzIkZzEkdDE3ODI3NTA5NjUkajYwJGwwJGgwJGRfUHZnUUl4U2ZnTFZMc3d3QXgxUnZ6YjJHanl2bXVYVXN3 Import all AMPS modules at once in TypeScript and log the client version. ```typescript // NPM installation: Import everything at once import * as amps from 'amps'; console.log(amps.Client.version()); ``` -------------------------------- ### transportFilter Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/client.html Sets or gets the transport filter to observe and optionally modify network messages. This is useful for inspecting traffic before encryption/decryption. ```APIDOC ## transportFilter ### Description Sets or gets the transport filter to observe incoming and outgoing messages in the format they are sent and received on the network. This allows you to inspect or modify outgoing messages before they are sent to the network, and incoming messages as they arrive from the network. This can be especially useful when using SSL connections, since this gives you a way to monitor outgoing network traffic before it is encrypted, and incoming network traffic after it is decrypted. ### Method Signature `transportFilter(): function` `transportFilter(transportFilter: function): Client` ### Parameters #### Setter Parameter - **transportFilter** (function) - Required - The function to set as the transport filter. It accepts `data` (any) and an optional `outgoing` (boolean) parameter and returns `void`. ### Request Example ```javascript const printingFilter = (data, outgoing) => { if (outgoing) { console.log('OUTGOING ---> ', data); } else { console.log('INCOMING ---> ', data); } }; const client = new Client().transportFilter(printingFilter); ``` ### Returns - **function**: The transport filter method if called without arguments. - **Client**: The client instance if a setter was called. ``` -------------------------------- ### options Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/messageheader.html Returns a comma-delimited list of options on a specific command. ```APIDOC ## options options(): string ### Description Returns a comma-delimited list of options on a specific command. ### Returns - **string** - The options value. ``` -------------------------------- ### ackBatchSize Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/client.html Sets or gets the acknowledgement batch size of the client. Batching acknowledgements reduces network traffic and improves performance. ```APIDOC ## ackBatchSize ### Description Sets or gets the acknowledgement batch size of the client. Batching acknowledgements reduces the number of round-trips to AMPS, which reduces network traffic and improves overall performance. AMPS sends the batch of acknowledgements when the number of acknowledgements exceeds a specified size. By default, if not specified otherwise, it is equal to 0. If the batch size value is greater than 1, the automatic ack timeout will be assigned with the default value of 1000 ms, if not already set. To override this behavior and disable ack timeouts with the batch size > 1, explicitly set ack timeout value to 0 after setting the batch size. ### Method (Getter) `ackBatchSize(): number` ### Method (Setter) `ackBatchSize(ackBatchSize: number): Client` ### Parameters (Setter) #### ackBatchSize: number ### Returns The client if a setter is called. The acknowledgement batch size otherwise. ### Request Example ```javascript // create a client and assign a publish store to it const client = new Client().ackBatchSize(100); // ... get the ack batch size later if (client.ackBatchSize() > 10) { ... } ``` ``` -------------------------------- ### Create and Populate a Publish Command Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/developer_guide/chapters/creating-commands.html Construct a publish command, setting the topic, data, and expiration for the message. ```javascript var command = new amps.command('publish') .topic('messages') .data({id: 1, hello: 'World'}) .expiration(5); ``` -------------------------------- ### Get Connect Wait Duration Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/fixeddelaystrategy.html This method returns the time in milliseconds that the client should delay before connecting to the given server URI. ```javascript getConnectWaitDuration(uri: string): number ``` -------------------------------- ### Command Constructor Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/command.html Initializes a new Command object with a specified command name. ```APIDOC ## constructor * new Command(command: string): Command * #### Parameters * ##### command: string The name of the command. #### Returns Command ``` -------------------------------- ### addAll Method Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/defaultserverchooser.html Adds multiple server URIs and optional authenticators to the chooser. ```APIDOC ## addAll ### Description This method allows to add as many server choosers as needed. The arguments can be either uri strings or objects that contain uri key, and optionally, the authenticator key. ### Parameters #### ...options: Array Either uri strings or objects that contain uri key, and optionally, the authenticator key. ### Returns DefaultServerChooser - The server chooser object. ``` -------------------------------- ### Subscribe to Messages Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/developer_guide/chapters/error-handling.html This snippet demonstrates setting up a subscription to receive messages. Errors occurring during message parsing within the client might be ignored if no error handler is set. ```javascript const onMessage = message => console.log(message.data); await client.subscribe(onMessage, 'pokes', '/Pokee LIKE ' + userId); ``` -------------------------------- ### lastChanceMessageHandler Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/client.html Sets or gets the last chance message handler. This handler is invoked when no other specific message handler matches an incoming message. ```APIDOC ## lastChanceMessageHandler ### Description Sets or gets the last chance message handler that is invoked when no other handler matches. ### Method Signature `lastChanceMessageHandler(): function` `lastChanceMessageHandler(lastChanceMessageHandler: function): Client` ### Parameters #### Path Parameters - **lastChanceMessageHandler** (function) - Optional - The function to be set as the last chance message handler. It accepts a `Message` object and returns `void`. - **message** (Message) - The incoming message object. ### Returns - `function` - The last chance message handler if called as a getter. - `Client` - The client object if called as a setter. ### Example ```javascript const client = new Client().lastChanceMessageHandler(message => { console.log('Last chance to handle the message: ', message.data); }); ``` ``` -------------------------------- ### Get Current Delimiter for FIX Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/fixtypehelper.html Use this method to retrieve the current delimiter value for FIX messages. The delimiter is returned as a string. ```javascript const delimiter = TypeHelper.helper('fix').delimiter(); ``` -------------------------------- ### Delta Subscribe using Convenience Method Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/developer_guide/chapters/deltas.html The `Client.deltaSubscribe()` convenience method simplifies the delta subscription process. If the `delta_subscribe` command is not valid for the topic, a regular subscription is created. ```javascript const subId = await client.deltaSubscribe( message => { /* ... */ }, // Message handler 'delta-topic', // Topic '/thingIWant = "true"' // Filter (optional) ); // Once subscribed, it resolves with the subscription id. console.log(subId); ``` -------------------------------- ### resubscriptionTimeout Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/defaultsubscriptionmanager.html Sets or gets the resubscription timeout value. The value must be zero or greater. A value of zero means it never times out. ```APIDOC ## resubscriptionTimeout ### Description This method sets/gets the resubscription timeout value. It should be bigger or equal to zero. If it is equal to zero, it never times out. ### Parameters * **timeout** (number) - Optional - Default value: 0. The timeout value (in milliseconds). ### Returns number The subscription timeout. ``` -------------------------------- ### Create AMPS Configuration Directory Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/quick_start/index.html Create a directory to store your AMPS server configuration files. ```bash $ mkdir ~/amps_dir/config ``` -------------------------------- ### sequenceId() Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/messageheader.html Returns an integer representing the publish message sequence number. Refer to the User Guide's Replication section for more details. ```APIDOC ## sequenceId() ### Description Returns an integer that corresponds to the publish message sequence number. For more information see the _Replication_ section in the _User Guide_. ### Returns - BigInteger: The sequenceId value. ``` -------------------------------- ### Subscription with Options Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/developer_guide/chapters/creating-commands.html Add options to a subscription by setting the 'Options' header. Consult the AMPS Command Reference for supported options. ```text Topic Options ``` -------------------------------- ### MessageHeader Constructor Source: https://devnull.crankuptheamps.com/documentation/api/js/5.3.4.0/api_reference/classes/messageheader.html Initializes a new MessageHeader instance. ```APIDOC ## constructor new MessageHeader(_header: Header): MessageHeader ### Description Initializes a new MessageHeader instance. ### Parameters #### _header: Header - **_header** (Header) - Description of the header parameter. #### Returns - **MessageHeader** - A new MessageHeader instance. ```