Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aws-amplify/pubsub

Package Overview
Dependencies
Maintainers
10
Versions
1968
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-amplify/pubsub

Pubsub category of aws-amplify

  • 1.3.1-ui-preview.12
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
410K
increased by7.2%
Maintainers
10
Weekly downloads
 
Created

What is @aws-amplify/pubsub?

@aws-amplify/pubsub is a part of the AWS Amplify library that provides a simple and powerful way to work with real-time messaging and event-driven architectures. It allows you to publish and subscribe to messages using AWS IoT, AWS AppSync, and other supported providers.

What are @aws-amplify/pubsub's main functionalities?

Publishing Messages

This feature allows you to publish messages to a specific topic. In this example, a message is published to 'myTopic' with the content 'Hello to all subscribers!'.

const { PubSub } = require('@aws-amplify/pubsub');

async function publishMessage() {
  await PubSub.publish('myTopic', { msg: 'Hello to all subscribers!' });
}

publishMessage();

Subscribing to Messages

This feature allows you to subscribe to a specific topic and receive messages. In this example, the subscription listens to 'myTopic' and logs any received messages.

const { PubSub } = require('@aws-amplify/pubsub');

PubSub.subscribe('myTopic').subscribe({
  next: data => console.log('Message received:', data),
  error: error => console.error(error),
  close: () => console.log('Done'),
});

Using AWS IoT

This feature allows you to use AWS IoT as a provider for PubSub. In this example, the AWS IoT provider is configured and used to subscribe to 'iotTopic'.

const { PubSub } = require('@aws-amplify/pubsub');
const { AWSIoTProvider } = require('@aws-amplify/pubsub/lib/Providers');

PubSub.addPluggable(new AWSIoTProvider({
  aws_pubsub_region: 'us-west-2',
  aws_pubsub_endpoint: 'wss://your-endpoint.iot.us-west-2.amazonaws.com/mqtt',
}));

PubSub.subscribe('iotTopic').subscribe({
  next: data => console.log('Message received:', data),
  error: error => console.error(error),
  close: () => console.log('Done'),
});

Other packages similar to @aws-amplify/pubsub

FAQs

Package last updated on 12 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc