LogoLogo
AMPS JavaScript Client 5.3.4
AMPS JavaScript Client 5.3.4
  • Welcome to the AMPS JavaScript Client
    • Before You Start
    • Obtaining and Installing the JavaScript Client
    • Your First AMPS Program
      • Client Identification
      • Connection Strings For AMPS
      • Providing Credentials to AMPS
    • Subscriptions
      • Content Filtering
        • Changing the Filter on a Subscription
      • Understanding Message Objects
      • Promises and Message Handlers
      • Regular Expression Subscriptions
      • Ending Subscriptions
    • Error Handling
      • Disconnect Handling
        • Using a Heartbeat to Detect Disconnection
        • Managing Disconnection
        • Replacing Disconnect Handling
      • Unhandled Errors
    • State of the World
      • SOW and Subscribe
      • Setting Batch Size
      • Managing SOW Contents
    • Using Queues
      • Backlog and Smart Pipelining
      • Acknowledging Messages
      • Acknowledgment Batching
      • Returning a Message to the Queue
      • Manual Acknowledgment
    • Delta Publish and Subscribe
      • Delta Subscribe
      • Delta Publish
    • High Availability
    • AMPS Programming: Working with Commands
    • Message Types
    • Advanced Topics
    • AMPS Server Documentation
    • API Documentation
Powered by GitBook

Get Help

  • FAQ
  • Legacy Documentation
  • Support / Contact Us

Get AMPS

  • Evaluate
  • Develop

60East Resources

  • Website
  • Privacy Policy

Copyright 2013-2024 60East Technologies, Inc.

On this page
Export as PDF
  1. Welcome to the AMPS JavaScript Client
  2. Subscriptions

Ending Subscriptions

With asynchronous message processing, when a subscription is successfully made, messages will begin flowing to the message handler function and the Client.subscribe() call returns a Promise object that resolves with a unique string that serves as the identifier for this subscription. A Client can have any number of active subscriptions, and this string is used to refer to the particular subscription we have made here. For example, to unsubscribe, we simply pass in this identifier:

const client = new Client('exampleClient');
await client.connect('wss://localhost:9000/amps/json');

const subId = await client.subscribe(onMessagePrinter, 'messages');

// when the program is done with the subscription, unsubscribe
await client.unsubscribe(subId);
console.log('Unsubscribed');

In this example, as in the previous section, we use the Client.subscribe() method to create a subscription to the messages topic. When our application is done listening to this topic, it unsubscribes by passing in the subId passed from the successfully resolved Promise of subscribe(). After the subscription is removed, no more messages will flow into our onMessagePrinter function.

AMPS also accepts the keyword all to unsubscribe all subscriptions for the client.

PreviousRegular Expression SubscriptionsNextError Handling

Last updated 3 months ago