# mulesoft WebSockets Connector - Full Documentation --- product: WebSockets Connector version: 1.0 is-latest-version: true --- # Troubleshooting WebSockets Connector > For the full documentation index, see: https://docs.mulesoft.com/llms.txt To troubleshoot Anypoint Connector for WebSockets (WebSockets Connector), become familiar with the information about enabling verbose logging and interpreting commonly thrown messages. ## Enable Verbose Logging To get a better understanding of why an application’s interaction with WebSockets Connector is failing, temporarily enable verbose logging for the connector. Remember to always disable the enhanced verbosity after troubleshooting because it affects your Mule application performance. To enable verbose logging in the configuration file: 1. Access Anypoint Studio and navigate to the **Package Explorer** view. 2. Open your application’s project name. 3. Open the `src/main/resources` path folder. 4. Open the `log4j2.xml` file inside the folder. 5. Add an `` tag inside the `` tag: ```xml ... ... ``` 6. Save your application changes. 7. Click the project name in **Package Explorer** and then click **Run** > **Run As** > **Mule Application**. ## Understand Common Throws Here is a list of common throw messages and how to interpret them: - WEBSOCKET:CONNECTIVITY The connection is no longer valid. Apply a reconnection policy if defined in the application setup. - WEBSOCKET:RETRY\_EXHAUSTED The maximum number of retries for the operation is reached. - WEBSOCKET:NO\_SUCH\_SOCKET The WebSocket cannot be referenced because the WebSocket ID does not exist. - WEBSOCKET:BASIC\_AUTHENTICATION The HTTP \*Request\* operation lacks basic authentication to send requests to the service, or the provided credentials are incorrect. - WEBSOCKET:FORBIDDEN The server refuses to give the requested resource because the client does not have access rights to the content. - WEBSOCKET:INTERNAL\_SERVER\_ERROR The server encountered a problem that prevented it from fulfilling the request. - WEBSOCKET:INVALID\_SOCKET\_ID The WebSocket ID is null or blank. - WEBSOCKET:NON\_UNIQUE\_SOCKET\_ID An error occurred while registering the WebSocket because the ID already exists. - WEBSOCKET:NOT\_FOUND The server could not find the requested resource. - WEBSOCKET:REMOTELY\_CLOSED The remote host closed the connection, which could be related to an SSL/TLS handshake issue. Check protocols, cipher suites, and certificate setup. Use -Djavax.net.debug=ssl for further debugging. - WEBSOCKET:SERVICE\_UNAVAILABLE The server is unable to manage the request because it is down for maintenance or overloaded. - WEBSOCKET:UNAUTHORIZED The authentication failed or has not yet been provided to get the requested response. ## See Also - [WebSockets Connector Reference](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-reference) - [Salesforce Help](https://help.salesforce.com) - [Known Issues](https://help.salesforce.com/s/issues) --- product: WebSockets Connector version: 1.0 is-latest-version: true --- # WebSockets Connection Close > For the full documentation index, see: https://docs.mulesoft.com/llms.txt This operation closes currently connected WebSockets referenced by a Socket ID. ```xml ``` ## Close Output This operation returns no payload or attributes. ## On Socket Closed A message source triggers a flow each time a WebSocket is closed. This is useful to perform cleanup operations, logging, or updating the app’s state. This is asynchronous. By the time the flow is invoked the socket has already been closed. Trying to send messages through the referenced WebSocket results in an error. ```xml ``` The path parameter indicates the path of sockets that when closed, trigger the flow. To indicate `catch-all`, you can use the asterisk wildcard symbol (∗). ## On Socket Closed Output This operation returns an empty payload and a WebSocketAttributes object in the attributes. ## See Also - [Salesforce Help](https://help.salesforce.com) - [Reconnection](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-reconnection) - [Server Components](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-server-components) - [WebSockets Connector Overview](https://docs.mulesoft.com/websockets-connector/latest/) --- product: WebSockets Connector version: 1.0 is-latest-version: true --- # WebSockets Connector > For the full documentation index, see: https://docs.mulesoft.com/llms.txt WebSockets Connector Version 1.0 Anypoint Connector for WebSockets (WebSockets Connector) includes these integration capabilities: - Establishes bidirectional and full-duplex communication between a server and client - Implements server push notifications - Seamlessly works on top of an existing HTTP infrastructure - Avoids the need for clients to regularly poll the server for new data A WebSocket is a bidirectional, TCP connection between a client and server that is kept open until the app closes it. With a WebSocket, an app uses HTTP to make an initial connection. The connection then gets upgraded to a TCP socket-based connection. Release Notes: [WebSockets Connector Release Notes](https://docs.mulesoft.com/release-notes/connector/websockets-connector-release-notes-mule-4) Exchange: [WebSockets Connector](https://www.mulesoft.com/exchange/com.mulesoft.connectors/mule-websockets-connector/) ## Advantages of Full-Duplex Communication In traditional HTTP, a connection is half-duplex (unidirectional) and works by using a request-response message exchange pattern: 1. A client connects to a server and sends a request. 2. The server processes the request and sends a response back. The connection ends after the client receives the response. Traditional HTTP connections require vast overhead because the client app is blocked until it receives a response from the server. Also, with this type of connection, the client must always initiate the request. Therefore, the server cannot push notifications to multiple apps at one time. When a client connects to a server using WebSockets, a persistent connection is established and kept open. Both the client and server can then send multiple messages to each other without needing to follow the HTTP request-response message exchange pattern. A WebSocket is built on top of the existing HTTP infrastructure, making it easy to reuse infrastructure that is already in place for traditional HTTP. See the [IETF document for RFC 6455 - the WebSocket protocol](https://datatracker.ietf.org/doc/html/rfc6455). ## Common WebSockets Connector Use Cases WebSockets Connector is useful for real-time apps that must avoid the overhead caused by the HTTP request-response message exchange pattern. Typical use cases for WebSockets Connector include chat apps and stock quote apps. ### Chat Apps In a chat app, as soon as a client sends a message to a chat group, subscribed participants want to receive that message immediately. If an app uses HTTP, the clients must constantly poll the server for available messages, which slows performance. With WebSockets, the server can push the available message to all subscribed users. ### Stock Quotes Apps Clients can open a WebSocket to a stock quote service, which continuously sends updated prices for a set of stocks. Because such prices change continuously, the ability to reuse the same connection and receive messages at random times make WebSockets an ideal solution for this problem. In this case, the client doesn’t send messages to the server after the connection has been established. ## Before You Begin Before creating an app, you must have access to the WebSockets target resource and Anypoint Platform. You must also understand how to create a Mule app using Anypoint Studio. ## Basic WebSockets Concepts The following concepts are integral to understanding how WebSockets Connector works: - [Socket types](#socket_types) - [Socket ID](#socket_id) - [Groups](#groups) - [Triggers](#triggers) - [Operations](#operations) ### Socket Types There are two types of WebSockets: - Inbound WebSocket created when the Mule app listens for incoming connections. In this scenario, an external system connects to an endpoint exposed by the Mule app. - Outbound WebSocket created when the Mule app connects to an external system. In this scenario, the Mule app initiates communication and asks an external system to establish a WebSocket. ### Socket ID All WebSockets, both inbound and outbound, have a unique socket ID that identifies them. The app must reference these IDs to operate on individual WebSockets. ### Groups WebSockets Connector introduces the concept of groups, which are string identifiers that individual WebSockets can optionally subscribe to. An app can use groups to broadcast one single message to a group of different WebSockets. Groups facilitate the process of identifying which WebSockets should participate in each broadcast. Subscriptions only exist in the context of each instance of a WebSockets Connector configuration. Therefore, when you establish WebSockets between a Mule app and a remote system, subscribing to WebSockets on Mule’s end of the connection to a group doesn’t affect the WebSockets on the remote system’s end. ## Triggers Triggers initiate the execution of a flow upon receiving a message or event notification. You can specify the following triggers for WebSockets-related events: - On New Inbound Message Exposes an endpoint that external systems can connect to and initiates the containing flow when a message is received. - On New Inbound Connection Initiates a flow when a new connection to the Inbound Listener is established. - On New Outbound Message Exposes an endpoint that initiates a flow when outbound WebSockets receive a message from an external system. - On Socket Closed Initiates the containing flow when inbound or outbound WebSockets close. ## Operations Anypoint Connector for WebSockets (WebSockets Connector) supports the following operations: - Open Outbound Socket Connects to an external system and creates an outbound WebSocket. - Send Sends a message through a WebSocket. - Subscribe Groups Subscribes a WebSocket to one or more groups. The app can invoke this operation on the same WebSocket multiple times, with each invocation being additive over the previous ones. Repeated groups are ignored. - Unsubscribe Groups Unsubscribes a WebSocket from one or more groups. You can invoke this operation multiple times on the same socket, with each invocation being additive over the previous ones. Repeated groups are ignored. - Broadcast Sends a message to multiple WebSockets classified by path, type, and group. - Close Socket Closes a WebSocket’s connection. - Bulk Close Socket Closes multiple WebSocket’s connections. ## Security WebSockets Connector supports securing the client and server endpoints through TLS, using the following URI schemes: - WS identifies a WebSocket server and resource name without using encryption (for example: `ws://localhost:80`). - WSS identifies a WebSocket server and resource name, secure through TLS (for example: `wss://localhost:433`). ## WebSockets Connector and Runtime Fabric When you develop a Mule app that uses WebSocket Connector and you deploy Mule into Runtime Fabric, there is no additional configuration required to enable WebSockets Connector in Runtime Fabric. ## See Also - [WebSockets Connector Configuration](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-config-topics) - [Salesforce Help](https://help.salesforce.com) --- product: WebSockets Connector version: 1.0 is-latest-version: true --- # WebSockets Connector Configuration > For the full documentation index, see: https://docs.mulesoft.com/llms.txt If your app exposes a WebSockets inbound endpoint, you need to set that up using the `` element. Because WebSockets connections are initiated with an HTTP Request, exposing a WebSockets inbound endpoint requires pointing to an underlying HTTP listener configuration. This not only allows you to reuse all the available features and configurations of an HTTP listener (such as host, port, TLS, etc.), it also allows your app to expose both WebSockets and regular HTTP endpoints using the same port. Using the HTTP listener configuration, you can specify base connection settings like a host, port, base path, or you can use it to configure a TLS based connection (WSS). ```xml ``` Notice the WebSockets server settings reference the HTTP listener configuration in the `listenerConfig` attribute. In this example, the WebSockets inbound listener listens for incoming messages on `localhost` and port 80, which are set in the HTTP listener configuration. This also sets basePath to `/ws` to override the HTTP basePath setting in the WebSockets configuration. To sum up, the WebSockets inbound listener listens for incoming messages at `ws://localhost:80/ws/chat`. Because the HTTP listener does not have a reference to a TLS configuration component, the connection opens by default using the WS protocol. ## Configure Server Timeouts WebSockets connections are persistent and stateful. Therefore, it’s a good practice to set a timeout to automatically close connections that have been idle. The following example shows how to use the `` to configure a 1-hour idle sockets timeout: ```xml ``` By default, all inbound sockets have an idle timeout of 15 minutes. ## Configure WebSockets Client If your application needs to connect to external WebSockets services, provide the client settings element: ```xml ``` In this example we have initialized an outbound socket which references the WebSockets client configuration ("wsClient") in the config-ref attribute. In this case, there is no need to reference an HTTP configuration. In the configuration above, a `host`, `port`, and `basePath` are specified to build the WS request URI. The `host` parameter is optional; if not set it is set to `localhost`. The `port` parameter is optional; if not specified the default value is set according to the protocol scheme. If WS is used, the default value is set to `80`. If WSS is used, the default is set to `443`. The `basePath` parameter is optional; if the URI is not set, it indicates the base path for all client requests relative to the indicated host and port. If the `basePath` parameter is not set, the default value is set to `/`. You can also specify a URL: ```xml ``` However, in this case a path cannot be indicated because the `URL` and `path` parameters are mutually exclusive. This is because URL indicates a full resource locator, while the path indicates a path relative to the host, port, and basePath. ## Default Parameters and Headers You can specify default headers and default query parameters in your client configuration to include in the connection request message. ```xml ``` You can also add headers or query parameters to your connect operation, which are sent along with the default headers and parameters in the request to establish a connection: ```xml ``` ## Configure Client Timeouts Just like for inbound connections, it’s a good practice to set a timeout to automatically close idle outbound connections. The following example shows how to use the `` to configure a 1-hour idle sockets timeout: ```xml ``` By default, outbound sockets have no idle timeout. However, the remote service they connect to is likely to have one. ### Combined Configuration If your app is doing both listening for incoming connections and issuing requests to external services, you can configure server and client together: ```xml ``` This configuration can be referenced from both inbound and outbound sockets. ```xml ``` ### TLS Configuration TLS (Transport Layer Security) allows for client and server apps to communicate through a secure channel and prevent attackers from eavesdropping or tampering with the transmitted data. In the case of the WebSockets server, TLS configuration is inherited from the referenced HTTP listener configuration, for example, to configure TLS on a WebSockets listener, point to `` with TLS configured. You first need to set up your truststore if your application connects to external services, or a keystore if your application listens for incoming connections, or you can set up both. In the following example, the WebSockets server inherits its TLS configuration from the HTTP listener, which in turn references `` to configure a key store: ```xml ``` In case of a WebSocket client, you can set up a truststore by directly referencing the `` in the `tlsConfig` property. ```xml ``` The `protocol` parameter is optional and defaults to WS (not secure). If set to `WSS`, then SSL is enabled in the connection. If `` was specified, then that configuration is used to create the SSL session. Otherwise, default settings are used. ## Next Now that you have completed configuration, you can try out the WebSockets [Examples](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-examples). ## See Also - [Salesforce Help](https://help.salesforce.com) - [WebSockets Connector Overview](https://docs.mulesoft.com/websockets-connector/latest/) - [CloudHub](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-cloudhub) - [XML and Maven](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-xml-maven) --- product: WebSockets Connector version: 1.0 is-latest-version: true --- # WebSockets Connector Examples > For the full documentation index, see: https://docs.mulesoft.com/llms.txt The following Mule app examples use Anypoint Connector for WebSockets (WebSockets Connector) to build an integration system that obtains and broadcasts stock quotes. ## Quote Producer App The following Mule app generates continuous random stock quotes. ![Quote Producer App flow in Anypoint Studio Canvas](/mulesoft/current/en-us/websockets-connector/latest/_images/websocket-example-1.png) 1. Stock quotes example: { "ticker": "CRM", "price": 157.6, "cur": "USD", "timestamp": 1563374475104 } - The `Quote` type identifies the previous mentioned stock quote sample. - The Mule app generates approximately 50 quotes with random stock prices that uses at least 5 different tickers, such as CRM, MELI, GOOG, NFLX and APPL. - The app also exposes the TLS secure `wss://localhost:60000/feed` endpoint that accepts only one connection. - The first client must connect to the endpoint successfully. - Subsequent clients that want to connect to the endpoint receive a WSS message with the text `"Sorry, spot taken"`. - Each produced quote is sent to the connected feed client. To generate the corresponding keystores: 1. Open your terminal. 2. In the terminal, navigate to the `src/main/resources` folder of your project app in Studio. 3. Run the following command: `keytool -genkey -v -keystore producer-keystore.jks -alias producerkey -keyalg RSA -keysize 2048 -validity 10000` ## XML for the Quote Producer App Paste this code into your Studio XML editor to quickly load the flow for this example into your Mule app: ```xml ``` ## Quote Aggregator App The following Mule app connects to the feed endpoint of the previous Quote Producer app and receives all of the quotes. Then, the Quote Aggregator app splits the quotes by ticker and places them in time-based aggregators that occur every 5 seconds. ![Quote Aggregator App flow in Anypoint Studio Canvas](/mulesoft/current/en-us/websockets-connector/latest/_images/websocket-example-2.png) When the aggregations occur, the aggregators output a reduced `Array` to a single `QuoteSnapshot` type. QuoteSnapshot Type example: ```json { "ticker": "CRM" "price": "157.54 USD" } ``` - The reduction occurs by picking the `Quote` with the greatest timestamp and transforming it. - The produced snapshots broadcast to a dynamic list of subscribers. - Subscriptions are done through the `wss://localhost:8082/quotes` endpoint that the Quote Aggregator App exposes. - Clients can connect to the previous endpoint by using a query parameter to indicate what stock quotes to follow, for example: `wss://localhost:8082/quotes?ticker=CRM&ticker=MELI` To generate the corresponding keystores and truststores: 1. Open your terminal. 2. In the terminal, navigate to the `src/main/resources` folder of your project app in Studio. 3. Run the following command for keystores: `keytool -genkey -v -keystore broadcast-keystore.jks -alias broadcast -keyalg RSA -keysize 2048 -validity 10000` 4. Run the following command to generate the truststores: `keytool -genkey -v -keystore aggregator-truststore.jks -alias broadcast -keyalg RSA -keysize 2048 -validity 10000` The request establishes a WebSocket that gets the snapshots for the `CRM` and `MELI` tickers. This is done should by subscribing the resulting sockets to the proper socket groups. To connect the Quote Aggregator app with the Quote Producer app, trigger the flow to open the outbound socket with the following command: \+ `curl -k [http://localhost:8081/connect](http://localhost:8081/connect)` ## XML for the Quote Aggregator App Paste this code into your Studio XML editor to quickly load the flow for this example into your Mule app: ```xml ``` ## Quote Client App The following Mule app opens at least three different WebSockets to the quotes endpoint in the Quote Aggregator app. Each of those sockets listen to a different set of tickers. ![Quote Client App flow in Anypoint Studio Canvas](/mulesoft/current/en-us/websockets-connector/latest/_images/websocket-example-3.png) Figure 1. Quote Client App flow The received `QuoteSnapshots` is transformed to CSV format and appended to a file. To generate the corresponding keystores: 1. Open your terminal. 2. In the terminal, navigate to the `src/main/resources` folder of your project app in Studio. 3. Run the following command: `keytool -genkey -v -keystore client-truststore.jks -alias client -keyalg RSA -keysize 2048 -validity 10000` To connect the Quote Client app with the Quote Aggregator app, trigger the flow to open the outbound socket with the following command: `curl -k [http://localhost:62000/open-aggregator-ws\?ticker\=CRM](http://localhost:62000/open-aggregator-ws\?ticker\=CRM)` ## XML for the Quote Client App Paste this code into your Studio XML editor to quickly load the flow for this example into your Mule app: ```xml ``` ## See Also - [Salesforce Help](https://help.salesforce.com) - [WebSocket Connector Configuration](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-config-topics) - [WebSocket Connector Server Components](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-server-components) - [WebSocket Connector Messaging Operations](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-messaging-operations) --- product: WebSockets Connector version: 1.0 is-latest-version: true --- # WebSockets Connector in CloudHub > For the full documentation index, see: https://docs.mulesoft.com/llms.txt You can deploy Mule apps that contain inbound WebSockets endpoints, outbound WebSockets endpoints, or both to CloudHub. If your app has inbound WebSockets endpoints only, to deploy the app in CloudHub you must: 1. Configure an Anypoint Virtual Private Cloud (VPC). 2. Set up a dedicated load balancer to route WS and WSS traffic through the Mule app. To set up the inbound WebSocket endpoints: 1. Configure the WebSockets inbound listener (``) to listen on one of the following ports: - `0.0.0.0`. - To communicate over WS, set the listener port to `8091`. - To communicate over WSS, set the listener port to `8092`. 2. Deploy your app to the VPC. 3. Set up the dedicated load balancer’s URL mapping rules to associate a URI to a specific app. For example, if your app is named 'my-websockets-mule-app', you can define a rule like the following: - Input Path: `/my-websockets-mule-app/` - Target App: `my-websockets-mule-app` - Output Path: `/` - Protocol: `ws` This rule routes all requests made to your dedicated load balancer’s URL and the specified input path to your Mule app’s root path `/`. The load balancer’s name determines its assigned URL, so for this example, if you name your load balancer `mylb`, then you would need to browse to: `ws://mylb.lb.anypointdns.net:80/my-websockets-mule-app/` to connect to your WebSockets Listener. The dedicated load balancer forwards all requests issued to port 80 to your app’s port 8091, which is destined for all WS connections. When using WSS, however, issue your requests to port 443, and these requests are forwarded to your Mule app’s port 8092. > [!NOTE] For CloudHub 2.0 deployments, a Mule app that supports websockets is deployed in the same > manner as any other Mule app deployed to CloudHub 2.0. For details, refer to > [Deploying Apps to CloudHub 2.0](https://docs.mulesoft.com/cloudhub-2/ch2-deploy). ## See Also - [Salesforce Help](https://help.salesforce.com) - [VPC Network Architecture](https://docs.mulesoft.com/cloudhub/vpc-architecture-concept) - [Dedicated Load Balancer Architecture](https://docs.mulesoft.com/cloudhub/lb-architecture) - [Dedicated Load Balancer Mapping Rules](https://docs.mulesoft.com/cloudhub/lb-mapping-rules) --- product: WebSockets Connector version: 1.0 is-latest-version: true --- # WebSockets Connector Reference > For the full documentation index, see: https://docs.mulesoft.com/llms.txt Support Version: [Select](https://www.salesforce.com/en-us/wp-content/uploads/sites/4/documents/legal/Agreements/versioning-back-support-policy.pdf) WebSockets Connector Version 1.0 Anypoint Connector for WebSockets (WebSockets Connector) provides communication through the WebSockets protocol, allowing external systems to open connections to the server (inbound sockets) or to establish connections to external systems (outbound socket). In both cases, full duplex traffic is supported. Release Notes: [WebSockets Connector Release Notes](https://docs.mulesoft.com/release-notes/connector/websockets-connector-release-notes-mule-4) ## Configurations --- ### Default Configuration Configure the name and connection types for the default configuration. #### Parameters
NameTypeDescriptionDefault ValueRequired

Name

String

The name for this configuration. Connectors reference the configuration with this name.

x

Connection

The connection types to provide to this configuration.

x

Name

String

The identifier of this element used to reference it in other components

x

#### Connection Types ##### Connection Configure the server, client, and reconnection parameters for the connection. ###### Parameters
NameTypeDescriptionDefault ValueRequired

Server Settings

Client Settings

Reconnection

When the application is deployed, a connectivity test is performed on all connectors. If set to true, deployment fails if the test doesn’t pass after exhausting the associated reconnection strategy.

## Operations Anypoint Connector for WebSockets (WebSockets Connector) supports the following operations: - [Broadcast](#Broadcast) - [Bulk Close Sockets](#BulkCloseSockets) - [Close Socket](#CloseSocket) - [Open Outbound Socket](#OpenOutboundSocket) - [Send](#Send) ### Associated Sources - [On New Inbound Message](#InboundListener) - [On New Inbound Connection](#OnInboundConnection) - [On Socket Closed](#OnSocketClosed) - [On New Outbound Message](#OutboundListener) ## Broadcast `` Sends the content to all active WebSockets that match the path, socketType, and groups criteria. In the case of the path, the configured base path is not considered, as you can target both inbound and outbound sockets. The message is sent to all the matching sockets, even though it’s possible that delivery to some of them fail. The operation returns a list of `BroadcastFailure` that contains details of each failure. If none fail, an empty list is returned. ### Parameters
NameTypeDescriptionDefault ValueRequired

Configuration

String

The name of the configuration to use

x

Content

Binary

The content to send

#[payload]

Path

String

The path of the sockets to match

x

Socket Type

Enumeration, one of:

  • INBOUND

  • OUTBOUND

  • ALL

The type of sockets to match

ALL

Groups

Array of String

Matches sockets that belong to any of these groups

Config Ref

ConfigurationProvider

The name of the configuration to use to execute this component

x

Target Variable

String

The name of a variable to store the operation’s output

Target Value

String

An expression to evaluate against the operation’s output and store the expression outcome in the target variable

#[payload]

Reconnection Strategy

A retry strategy in case of connectivity errors

### Output

Type

Array of Broadcast Failure

### For Configurations - [Default Configuration](#Config) ### Throws - WEBSOCKET:CONNECTIVITY - WEBSOCKET:RETRY\_EXHAUSTED ## Bulk Close Sockets `` ### Parameters
NameTypeDescriptionDefault ValueRequired

Configuration

String

The name of the configuration to use

x

Socket Type

Enumeration, one of:

  • INBOUND

  • OUTBOUND

  • ALL

ALL

Groups

Array of String

Close Code

Enumeration, one of:

  • NORMAL_CLOSURE

  • ENDPOINT_GOING_DOWN

  • PROTOCOL_ERROR

  • INVALID_DATA

  • MESSAGE_TOO_LARGE

NORMAL_CLOSURE

Reason

String

Config Ref

ConfigurationProvider

The name of the configuration to use to execute this component

x

Reconnection Strategy

A retry strategy in case of connectivity errors

### For Configurations - [Default Configuration](#Config) ### Throws - WEBSOCKET:CONNECTIVITY - WEBSOCKET:RETRY\_EXHAUSTED ## Close Socket `` This operation closes the socket. ### Parameters
NameTypeDescriptionDefault ValueRequired

Configuration

String

The name of the configuration to use

x

Socket Id

String

The ID of the socket to close

x

Close Code

Enumeration, one of:

  • NORMAL_CLOSURE

  • ENDPOINT_GOING_DOWN

  • PROTOCOL_ERROR

  • INVALID_DATA

  • MESSAGE_TOO_LARGE

The close code

NORMAL_CLOSURE

Reason

String

The closing reason phrase

Config Ref

ConfigurationProvider

The name of the configuration to use to execute this component

x

Reconnection Strategy

A retry strategy in case of connectivity errors

### For Configurations - [Default Configuration](#Config) ### Throws - WEBSOCKET:CONNECTIVITY - WEBSOCKET:NO\_SUCH\_SOCKET - WEBSOCKET:RETRY\_EXHAUSTED ## Open Outbound Socket `` This operation opens a new outbound socket. ### Parameters
NameTypeDescriptionDefault ValueRequired

Configuration

String

The name of the configuration to use

x

Socket Id

String

Default Groups

Array of String

The groups to which the socket should initially subscribe

Config Ref

ConfigurationProvider

The name of the configuration to use to execute this component

x

Path

String

Path where the request is sent

URL

String

URL where to send the request

Headers

Object

HTTP headers the message should include

URI Parameters

Object

URI parameters to use to create the request

Query Parameters

Object

Query parameters the request should include

Target Variable

String

The name of a variable to store the operation’s output

Target Value

String

An expression to evaluate against the operation’s output and store the expression outcome in the target variable

#[payload]

Reconnection Strategy

A retry strategy in case of connectivity errors

### Output

Type

String

Attributes Type

### For Configurations - [Default Configuration](#Config) ### Throws - WEBSOCKET:BASIC\_AUTHENTICATION - WEBSOCKET:CONNECTIVITY - WEBSOCKET:FORBIDDEN - WEBSOCKET:INTERNAL\_SERVER\_ERROR - WEBSOCKET:INVALID\_SOCKET\_ID - WEBSOCKET:NO\_SUCH\_SOCKET - WEBSOCKET:NON\_UNIQUE\_SOCKET\_ID - WEBSOCKET:NOT\_FOUND - WEBSOCKET:REMOTELY\_CLOSED - WEBSOCKET:RETRY\_EXHAUSTED - WEBSOCKET:SERVICE\_UNAVAILABLE - WEBSOCKET:UNAUTHORIZED ## Send `` Sends the content through a specified socket. ### Parameters
NameTypeDescriptionDefault ValueRequired

Configuration

String

The name of the configuration to use

x

Socket Id

String

The ID of the socket through which to send data

x

Content

Binary

The content to send

#[payload]

Config Ref

ConfigurationProvider

The name of the configuration to use to execute this component

x

Reconnection Strategy

A retry strategy in case of connectivity errors

### For Configurations - [Default Configuration](#Config) ### Throws - WEBSOCKET:CONNECTIVITY - WEBSOCKET:NO\_SUCH\_SOCKET - WEBSOCKET:RETRY\_EXHAUSTED ## Sources ## On New Inbound Message `` Exposes an endpoint through which external systems can connect through a WebSocket. This source triggers the owning flow each time one of those WebSockets sends information to this server. Additionally, any `websocket:on-inbound-connection` component with a matching path triggers when a socket connection is established. ### Parameters
NameTypeDescriptionDefault ValueRequired

Configuration

String

The name of the configuration to use

x

Path

String

Relative path from the path set in the configuration

x

Default Groups

Array of String

The groups to which newly created sockets should initially subscribe

Output Mime Type

String

The MIME type of the payload that this operation outputs

Output Encoding

String

The encoding of the payload that this operation outputs

Config Ref

ConfigurationProvider

The name of the configuration to use to execute this component

x

Primary Node Only

Boolean

Whether this source should be executed only on the primary node when running in a cluster

Streaming Strategy

Configure to use repeatable streams

Redelivery Policy

Defines a policy for processing the redelivery of the same message

Reconnection Strategy

A retry strategy in case of connectivity errors

### Output

Type

Any

Attributes Type

### For Configurations - [Default Configuration](#Config) ## On New Inbound Connection `` Triggers when an inbound WebSocket connection is established. ### Parameters
NameTypeDescriptionDefault ValueRequired

Configuration

String

The name of the configuration to use

x

Path

String

Relative path from the path set in the configuration

x

Config Ref

ConfigurationProvider

The name of the configuration to use to execute this component

x

Primary Node Only

Boolean

Whether this source should be executed only on the primary node when running in a cluster

Redelivery Policy

Defines a policy for processing the redelivery of the same message

Reconnection Strategy

A retry strategy in case of connectivity errors

### Output

Type

String

Attributes Type

### For Configurations - [Default Configuration](#Config) ## On Socket Closed `` Triggers when a WebSocket is closed. ### Parameters
NameTypeDescriptionDefault ValueRequired

Configuration

String

The name of the configuration to use

x

Path

String

Relative path from the path set in the configuration

x

Config Ref

ConfigurationProvider

The name of the configuration to use to execute this component

x

Primary Node Only

Boolean

Whether this source should be executed only on the primary node when running in a cluster

Redelivery Policy

Defines a policy for processing the redelivery of the same message

Reconnection Strategy

A retry strategy in case of connectivity errors

### Output

Type

Closed Connection Event

Attributes Type

### For Configurations - [Default Configuration](#Config) ## On New Outbound Message `` Triggers when an outbound socket receives a message. ### Parameters
NameTypeDescriptionDefault ValueRequired

Configuration

String

The name of the configuration to use

x

Path

String

Relative path from the path set in the configuration

x

Output Mime Type

String

The MIME type of the payload that this operation outputs

Output Encoding

String

The encoding of the payload that this operation outputs

Config Ref

ConfigurationProvider

The name of the configuration to use to execute this component

x

Primary Node Only

Boolean

Whether this source should be executed only on the primary node when running in a cluster

Streaming Strategy

Configure to use repeatable streams

Redelivery Policy

Defines a policy for processing the redelivery of the same message

Reconnection Strategy

A retry strategy in case of connectivity errors

### Output

Type

Any

Attributes Type

### For Configurations - [Default Configuration](#Config) ## Types ### WebSocket Server Settings
FieldTypeDescriptionDefault ValueRequired

Listener Base Path

String

Base path to use for all resources served through this config.

/

Listener Config

String

Reference to the http:listener-config used to expose the inbound endpoint

x

Idle Socket Timeout

Number

Timeout for automatically closing idle WebSockets

15

Idle Socket Timeout Unit

Enumeration, one of:

  • NANOSECONDS

  • MICROSECONDS

  • MILLISECONDS

  • SECONDS

  • MINUTES

  • HOURS

  • DAYS

Time unit that qualifies the #idleSocketTimeout

MINUTES

### WebSocket Client Settings
FieldTypeDescriptionDefault ValueRequired

Host

String

Host where the requests is sent

Port

Number

Port where the requests is sent. If the protocol attribute is WS (default), then the default value is 80. If the protocol attribute is WSS, then the default value is 443.

Base Path

String

Base path to use for all outbound sockets that reference this config

/

Protocol

Enumeration, one of:

  • WS

  • WSS

Protocol to use for outbound communication. Valid values are WS and WSS. Default value is WS. When using WSS, the HTTP communication is secured using TLS/SSL. If WSS is configured as the protocol, then the user can customize the TLS/SSL configuration by defining the tls:context parameter. If tls:context is not defined, then the default JVM certificates are used to establish communication.

WS

Tls Context

Reference to a TLS config element that enables WSS for outbound sockets

Default Headers

Array of Header

Default HTTP headers the message should include

Default Query Params

Array of Query Param

Default query parameters the request should include

Connection Idle Timeout

Number

A timeout for idle connections to be closed. If not specified, there is no timeout.

Connection Idle Timeout Unit

Enumeration, one of:

  • NANOSECONDS

  • MICROSECONDS

  • MILLISECONDS

  • SECONDS

  • MINUTES

  • HOURS

  • DAYS

Timeout unit that qualifies the #connectionIdleTimeout

MINUTES

Follow Redirects

Boolean

Specifies whether or not to follow redirects.

true

Preserve Headers Case

Boolean

By default, header keys are stored internally in lower-case. This is to improve performance of headers handling and is functionally correct as specified in the RFC.

If a server expects headers in a specific case, set this flag to `true` to preserve the case of the header keys.

false

Max Connections

Number

The maximum number of outbound connections that will be kept open at the same time. By default the number of connections is unlimited.

-1

Proxy Config

Reusable configuration element for outbound connections through a proxy. A proxy element must define host name and port attributes, and, optionally, can define a username and a password.

Authentication

HttpRequestAuthentication

Authentication method to use for the HTTP request

### Tls
FieldTypeDescriptionDefault ValueRequired

Enabled Protocols

String

A comma-separated list of protocols enabled for this context

Enabled Cipher Suites

String

A comma-separated list of cipher suites enabled for this context

Trust Store

Key Store

Revocation Check

### Trust Store
FieldTypeDescriptionDefault ValueRequired

Path

String

The location (which will be resolved relative to the current classpath and file system, if possible) of the trust store

Password

String

The password used to protect the trust store

Type

String

The type of store used

Algorithm

String

The algorithm used by the trust store

Insecure

Boolean

If set to true, no certificate validations are performed, which renders connections vulnerable to attacks. Use at your own risk.

### Key Store
FieldTypeDescriptionDefault ValueRequired

Path

String

The location (which will be resolved relative to the current classpath and file system, if possible) of the key store

Type

String

The type of store used

Alias

String

When the key store contains many private keys, this attribute indicates the alias of the key to use. If not defined, the first key in the file is used by default.

Key Password

String

The password used to protect the private key

Password

String

The password used to protect the key store

Algorithm

String

The algorithm used by the key store

### Standard Revocation Check
FieldTypeDescriptionDefault ValueRequired

Only End Entities

Boolean

Verify only the last element of the certificate chain

Prefer Crls

Boolean

Try CRL (instead of OCSP) first

No Fallback

Boolean

Do not use the secondary checking method (the one not selected before)

Soft Fail

Boolean

Avoid verification failure when the revocation server can not be reached or is busy

### Custom Ocsp Responder
FieldTypeDescriptionDefault ValueRequired

Url

String

The URL of the OCSP responder

Cert Alias

String

Alias of the signing certificate for the OCSP response (must be in the trust store), if present

### CRL File
FieldTypeDescriptionDefault ValueRequired

Path

String

The path to the CRL file.

### Header
FieldTypeDescriptionDefault ValueRequired

Key

String

x

Value

String

x

### Query Param
FieldTypeDescriptionDefault ValueRequired

Key

String

x

Value

String

x

### Reconnection
FieldTypeDescriptionDefault ValueRequired

Fails Deployment

Boolean

When the application is deployed, a connectivity test is performed on all connectors. If set to true, deployment fails if the test doesn’t pass after exhausting the associated reconnection strategy.

Reconnection Strategy

The reconnection strategy to use.

### Reconnect
FieldTypeDescriptionDefault ValueRequired

Frequency

Number

How often in milliseconds to reconnect

Blocking

Boolean

If false, the reconnection strategy will run in a separate, non-blocking thread

Count

Number

How many reconnection attempts to make.

### Reconnect Forever
FieldTypeDescriptionDefault ValueRequired

Frequency

Number

How often in milliseconds to reconnect

Blocking

Boolean

If false, the reconnection strategy will run in a separate, non-blocking thread

### Inbound WebSocket Attributes
FieldTypeDescriptionDefault ValueRequired

Version

String

HTTP version of the request

x

Local Address

String

Local host address from the server

x

Remote Address

String

Remote host address from the sender

x

Client Certificate

Any

Client certificate (if two-way TLS is enabled)

Socket Id

String

The socket ID

x

Socket Type

Enumeration, one of:

  • INBOUND

  • OUTBOUND

The socket type

x

Groups

Array of String

The groups on which this socket is subscribed

x

Path

String

Full path where the request was received

x

Request Uri

String

Full URI of the request

x

Scheme

Enumeration, one of:

  • WS

  • WSS

HTTP scheme of the request.

x

Query Params

Object

Query parameters map built from the parsed string

x

Headers

Object

Headers map built from the parsed string

x

Uri Params

Object

URI parameters extracted from the request path

x

Method

String

HTTP method of the request

x

Query String

String

Query string of the request

x

### Repeatable In Memory Stream
FieldTypeDescriptionDefault ValueRequired

Initial Buffer Size

Number

The amount of memory to allocate to consume the stream and provide random access to it. If the stream contains more data than can be fit into this buffer, then the buffer expands according to the bufferSizeIncrement attribute, with an upper limit of maxInMemorySize.

Buffer Size Increment

Number

This is by how much the buffer size expands if it exceeds its initial size. Setting a value of zero or lower means that the buffer should not expand, meaning that a STREAM_MAXIMUM_SIZE_EXCEEDED error is raised when the buffer gets full.

Max Buffer Size

Number

The maximum amount of memory to use. If more than that is used then a STREAM_MAXIMUM_SIZE_EXCEEDED error is raised. A value lower than or equal to zero means no limit.

Buffer Unit

Enumeration, one of:

  • BYTE

  • KB

  • MB

  • GB

The unit in which all these attributes are expressed

### Repeatable File Store Stream
FieldTypeDescriptionDefault ValueRequired

In Memory Size

Number

Defines the maximum memory that the stream should use to keep data in memory. If more than that is consumed then it will start to buffer the content on disk.

Buffer Unit

Enumeration, one of:

  • BYTE

  • KB

  • MB

  • GB

The unit in which maxInMemorySize is expressed

### Redelivery Policy
FieldTypeDescriptionDefault ValueRequired

Max Redelivery Count

Number

The maximum number of times a message can be redelivered and processed unsuccessfully before triggering a process-failed-message

Message Digest Algorithm

String

The secure hashing algorithm to use.

SHA-256

Message Identifier

Defines which strategy is used to identify the messages

Object Store

ObjectStore

The object store where the redelivery counter for each message is stored

### Redelivery Policy Message Identifier
FieldTypeDescriptionDefault ValueRequired

Use Secure Hash

Boolean

Whether to use a secure hash algorithm to identify a redelivered message

Id Expression

String

Defines one or more expressions to use to determine when a message has been redelivered. This property can be set only if useSecureHash is false.

### WebSocket Attributes
FieldTypeDescriptionDefault ValueRequired

Socket Id

String

The socket ID

x

Socket Type

Enumeration, one of:

  • INBOUND

  • OUTBOUND

The socket type

x

Groups

Array of String

The groups to which this socket is subscribed

x

Path

String

Full path where the request was received

x

Request Uri

String

Full URI of the request

x

Scheme

Enumeration, one of:

  • WS

  • WSS

HTTP scheme of the request.

x

Query Params

Object

Query parameters map built from the parsed string

x

Headers

Object

Headers map built from the parsed string

x

Uri Params

Object

URI parameters extracted from the request path

x

Method

String

HTTP method of the request

x

Query String

String

Query string of the request

x

### Closed Connection Event
FieldTypeDescriptionDefault ValueRequired

Code

Enumeration, one of:

  • NORMAL_CLOSURE

  • ENDPOINT_GOING_DOWN

  • PROTOCOL_ERROR

  • INVALID_DATA

  • MESSAGE_TOO_LARGE

The close code

x

Reason

String

The phrase with the reason the socket was closed

### Broadcast Failure
FieldTypeDescriptionDefault ValueRequired

Error Message

String

Exception

Any

Socket Id

String

Type

Enumeration, one of:

  • INBOUND

  • OUTBOUND

Uri

String

### Proxy
FieldTypeDescriptionDefault ValueRequired

Host

String

Host where the proxy requests is sent

x

Port

Number

Port where the proxy requests is sent

x

Username

String

The username to authenticate against the proxy

Password

String

The password to authenticate against the proxy

Non Proxy Hosts

String

A list of comma-separated hosts against which the proxy should not be used

### NTLM Proxy
FieldTypeDescriptionDefault ValueRequired

Ntlm Domain

String

The domain to authenticate against the proxy

x

Host

String

Host where the proxy requests is sent

x

Port

Number

Port where the proxy requests is sent

x

Username

String

The username to authenticate against the proxy

Password

String

The password to authenticate against the proxy

Non Proxy Hosts

String

A list of comma-separated hosts against which the proxy should not be used

## See Also - [WebSocket Connector Overview](https://docs.mulesoft.com/websockets-connector/latest/) - [Salesforce Help](https://help.salesforce.com) --- product: WebSockets Connector version: 1.0 is-latest-version: true --- # WebSockets Connector XML and Maven Support > For the full documentation index, see: https://docs.mulesoft.com/llms.txt Although you can manually code a Mule app in XML, it is more efficient to use Anypoint Studio. If you manually code a Mule runtime engine (Mule) app in XML, either from the Anypoint Studio XML editor or from a text editor, you can get access to the connector in your app by adding reference statements to both your XML Mule flow and the Apache Maven `pom.xml` file. When you add the connector in Studio, Studio automatically populates the XML code with the connector’s namespace and schema location. It also adds a dependency to the `pom.xml` file. ## Add a Namespace for the Connector Paste the following code inside the `` tag of the header of your configuration XML: ```xml http://www.mulesoft.org/schema/mule/websocket http://www.mulesoft.org/schema/mule/websocket/current/mule-websocket.xsd ``` This example shows how the namespace statements are placed in the `` XML block: ```xml ``` ## Add a POM File Dependency The Apache Maven `pom.xml` file generated by Anypoint Studio contains dependencies for a Mule app. If you code a Mule app manually, include this XML snippet in your `pom.xml` file to enable access to this connector: ```xml com.mulesoft.connectors mule-websockets-connector x.x.x mule-plugin ``` Replace `x.x.x` with the version that corresponds to the connector you are using. To obtain the most up-to-date `pom.xml` file information: 1. Go to [Anypoint Exchange](https://www.mulesoft.com/exchange/). 2. In Exchange, click **Login** and supply your Anypoint Platform username and password. 3. In Exchange, search for `websockets`. 4. Select the connector. 5. Click **Dependency Snippets** near the upper right of the screen. ## Next Step After completing your namespace and `pom.xml` file, you can try the [Examples](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-examples). ## See Also - [Introduction to Anypoint Connectors](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors) - [Salesforce Help](https://help.salesforce.com) --- product: WebSockets Connector version: 1.0 is-latest-version: true --- # WebSockets Managing Groups > For the full documentation index, see: https://docs.mulesoft.com/llms.txt The WebSockets Connector uses socket groups, which are String identifiers that WebSockets clients can optionally subscribe to. This is useful for what we call message segregation, which enables your app to broadcast a single message to a group of different WebSockets clients. Examples of how to leverage groups can be found in the documentation of the broadcast operation. Both the `` trigger and the `` operation allow to specify default groups. That is groups that every new inbound and outbound sockets will be automatically subscribed to. There are also use cases that require manually subscribing or unsubscribing a socket from a group. For example, imagine the use case of a multi-tenant application in which an inbound WebSocket is established. The initiator HTTP request includes an authentication header called `clientId`. We call a flow called `fetch-client-details` which validates a client ID and sets a variable called `orgId` that identifies the organization the client belongs to. The socket is added to a group that identifies its organization. Group subscription is dynamic because the group to be subscribed to (the organization ID) can only be determined at runtime. An example of a flow: ```xml ``` The flip side of this use case is that you also need to dynamically unsubscribe from a group, which can be achieved with the `` operation: ```xml ``` ## See Also - [Salesforce Help](https://help.salesforce.com) - [WebSockets Connector Overview](https://docs.mulesoft.com/websockets-connector/latest/) - [Connector Configuration](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-config-topics) - [Messaging Operations](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-messaging-operations) --- product: WebSockets Connector version: 1.0 is-latest-version: true --- # WebSockets Messaging Operations > For the full documentation index, see: https://docs.mulesoft.com/llms.txt ## Send Operation The Send operation allows you to send a message through a WebSocket identified by its socket ID after a connection is established. This operation can be used for both inbound and outbound WebSocket instances. ```xml 'Good morning!' #['Good morning ' ++ attributes.socketId ++ '!'] ``` ## Broadcast Operation The Broadcast operation sends a message to a group of sockets. To select the group of sockets to which the message can be broadcast: - Subscribe to specific groups - Connect to a specific path - Be of a specific type (INBOUND or OUTBOUND) The type and group parameters work in tandem, in an additive way. They are both optional and can be used separately, but when used together they act as two levels of filtering: ```xml ``` ### Output The output of the Broadcast operation is void. ## See Also - [Salesforce Help](https://help.salesforce.com) - [WebSockets Connector Overview](https://docs.mulesoft.com/websockets-connector/latest/) - [Manage Groups](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-managing-groups) - [Connector Configuration](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-config-topics) --- product: WebSockets Connector version: 1.0 is-latest-version: true --- # WebSockets Reconnection > For the full documentation index, see: https://docs.mulesoft.com/llms.txt WebSockets are based on persistent and stateful connections. A connection can abnormally close in the lapse between when it was established and its use in an operation due to factors like idle timeouts, network conditions, and more. Inbound sockets cannot be automatically reconnected because the remote system must resend the connection request for the connections to be reestablished. For outbound sockets however, a reconnection policy can be used to re-establish the connection in case it drops. When your Mule app tries to use a WebSocket that has been abnormally closed, for example to send a message to the socket, reconnection is re-established by replaying the same HTTP request that originally established the outbound socket. After which, the operation is automatically retried. The following example shows how to send a reconnection policy using a `` operation so that reconnection re-attempts once every second up to 5 times in case the connection is dropped: ```xml Hello World! ``` ## See Also - [Salesforce Help](https://help.salesforce.com) - [WebSockets Connector Overview](https://docs.mulesoft.com/websockets-connector/latest/) - [Connector Configuration](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-config-topics) --- product: WebSockets Connector version: 1.0 is-latest-version: true --- # WebSockets Server Components > For the full documentation index, see: https://docs.mulesoft.com/llms.txt ## Inbound Listener The Inbound Listener component represents a WebSocket endpoint that clients can connect to. By browsing to this endpoint, external clients establish a WebSocket connection, and trigger the flow each time they send a message. Clients can also indicate the default groups that this endpoint automatically subscribes to in the defaultGroups parameter. If any broadcast operations are performed to these groups, this endpoint receives and processes them. This subscription is done inside the app domain, which means that adding the default groups parameter dows not send information about this subscription to the outbound WebSocket counterparts. This is because the groups feature is not part of WS protocol. When you subscribe an inbound WebSocket to a group, if one WebSocket within your app domain wants to send a message to all other WebSockets, your app domain also has to be subscribed to the specified groups. In short, group subscription only affects WebSockets residing in the same app domain, and WebSockets from external applications are not subscribed by a Mule app to any other groups. ```xml #['I'm fine, thank you!'] #['Hi! How are you?'] ``` ## Send a Response Unlike the `` element that automatically sends a response when a flow ends, this component never automatically sends a response. This is because the WebSocket protocol is full duplex and therefore provides no guarantee that you need to or want to send a response. Depending on your use case, you might want to process the messages without sending a response, or only send responses on certain cases. If you want to send a response, use the `` operation. ### Output Each time a new message arrives, the flow triggers with a message, and the payload contains the message’s content. The message’s MIME type is obtained from the `Content-Type` header of the HTTP request. If the MIME type hasn’t been set, the MIME type defaults to one of the following depending on the protocol’s DataFrame type: - If binary, defaults MIME to `application/octect-stream` - If text, defaults MIME to `text/plain` The attributes contain a WebSockets attributes object. ## On Inbound Connection This is a message source that triggers each time an INBOUND WebSockets connection is established. You can only have one of these sources for a given path and it requires that a matching inbound listener exist for the path. This is useful to perform post-connect tasks such as logging or assigning the socket with a group. This flow triggers synchronously. By the time this flow is invoked, the socket has already been established and it could potentially be broadcasting or receiving messages. Those messages are queued and not delivered to any flow until the event triggered by the source completes. If it fails, all queued messages are discarded and the connection is dropped. This message source has two main use cases: - Keep track of the generated socket IDs for later use - Have a validation point in which WebSockets can be rejected before it becomes usable to the application For example, the following flow validates attributes from the originating request and decides to close the connection if the validation doesn’t pass. ```xml ``` ## See Also - [WebSockets Connector Overview](https://docs.mulesoft.com/websockets-connector/latest/) - [Server Components](#) - [Messaging Operations](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-messaging-operations) - [Salesforce Help](https://help.salesforce.com) --- product: WebSockets Connector version: 1.0 is-latest-version: true --- # WebSockets Studio Configuration > For the full documentation index, see: https://docs.mulesoft.com/llms.txt To configure the connector in Anypoint Studio: 1. Add the connector to a Studio project. 2. Configure the connector. 3. Configure an input source for the connector. ## Add the Connector to a Studio Project Anypoint Studio provides two ways to add the connector to your Studio project: from the Exchange button in the Studio taskbar or from the Mule Palette view. ### Add the Connector Using Exchange 1. In Studio, create a Mule project. 2. Click the Exchange icon **(X)** in the upper-left of the Studio task bar. 3. In Exchange, click **Login** and supply your Anypoint Platform username and password. 4. In Exchange, search for "websockets". 5. Select the connector and click **Add to project**. 6. Follow the prompts to install the connector. ### Add the Connector in Studio 1. In Studio, create a Mule project. 2. In the Mule Palette view, click **(X) Search in Exchange**. 3. In **Add Modules to Project**, type "websockets" in the search field. 4. Click this connector’s name in **Available modules**. 5. Click **Add**. 6. Click **Finish**. ## Configure the Connector 1. Go to the **Global Elements** tab, and click **Create**. 2. From **Connector Configuration**, select the **WebSockets Config**. 3. If you want your connector to listen for incoming requests check the **Configure Inbound WebSocket** section. If you want to perform requests to external services, check the **Configure Outbound WebSocket** section. You can check both if your application will be doing both inbound and outbound connections. ### Configure Inbound WebSockets 1. Go to the **Global Elements** tab and click **Create**. 2. From **Connector Configuration**, select the **HTTP Listener Config**. 3. In your WebSockets Configuration, check the **Server settings** box. 4. Specify the listener base path(optional) and reference the HTTP Listener Config you created before. ### Configure Outbound WebSockets 1. In your WebSockets Configuration, check the **Client settings** box. 2. Specify the following optional properties: - Host - Port - Path 3. In the **Default Headers** and **Query Parameters** sections you can introduce your default values for headers and query parameters by selecting an option from the drop-down list. 1. Select **Expression** to enter a `dwl` expression. 2. Click **Edit Inline** to enter key/value pairs by clicking the '+' sign. ## Configure an Input Source Configure an input source for the connector. You can put the following operations for the connector in the **Source** area of the Studio canvas: - Inbound Listener - On Outbound Socket Message - On Inbound Connection (requires an Inbound Listener) - On Socket Closed ## Next Now that you have completed configuring Studio, see the [Connector Configuration](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-config-topics) for more configuration ideas. ## See Also - [Salesforce Help](https://help.salesforce.com) - [WebSockets Connector Overview](https://docs.mulesoft.com/websockets-connector/latest/) - [XML and Maven Configuration](https://docs.mulesoft.com/websockets-connector/latest/websockets-connector-xml-maven)