Skip to content

JS Sample update on Guaranteed Publisher/Subscriber and Queue Producer/Consumer #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The "Getting Started" tutorials will get you up to speed and sending messages wi

- Follow [these instructions](https://cloud.solace.com/learn/group_getting_started/ggs_signup.html) to quickly spin up a cloud-based Solace messaging service for your applications.
- Follow [these instructions](https://docs.solace.com/Solace-SW-Broker-Set-Up/Setting-Up-SW-Brokers.htm) to start the Solace PubSub+ software event broker in leading Clouds, Container Platforms or Hypervisors. The tutorials outline where to download and how to install the Solace PubSub+ software event broker.
- If your company has Solace message routers deployed, contact your middleware team to obtain the host name or IP address of a Solace message router to test against, a username and password to access it, and a VPN in which you can produce and consume messages.
- If your company has Solace PubSub+ Event Brokers deployed, contact your middleware team to obtain the host name or IP address of a Solace PubSub+ Event Broker to test against, a username and password to access it, and a VPN in which you can produce and consume messages.

## Contents

Expand All @@ -19,10 +19,10 @@ This repository contains:
- [Publish/Subscribe](https://tutorials.solace.dev/javascript/publish-subscribe/): Learn how to set up pub/sub messaging on a Solace PubSub+ software event broker.
- [Persistence](https://tutorials.solace.dev/javascript/persistence-with-queues/): Learn how to set up persistence for guaranteed delivery.
- [Request/Reply](https://tutorials.solace.dev/javascript/request-reply/): Learn how to set up request/reply messaging.
- [Confirmed Delivery](https://tutorials.solace.dev/javascript/confirmed-delivery/): Learn how to confirm that your messages are received by a Solace message router.
- [Confirmed Delivery](https://tutorials.solace.dev/javascript/confirmed-delivery/): Learn how to confirm that your messages are received by a Solace PubSub+ Event Broker.
- [Topic to Queue Mapping](https://tutorials.solace.dev/javascript/topic-to-queue-mapping/): Learn how to map existing topics to Solace queues.

* The following additional samples showing how to make use of advanced features of the Solace message router.
* The following additional samples showing how to make use of advanced features of the Solace PubSub+ Event Broker.

- [Secure Session](https://github.com/SolaceSamples/solace-samples-javascript/tree/master/src/features/SecureSession): Learn how to use secure connection to the server and server and client certificate authentication.
- [Active Consumer Indication](https://tutorials.solace.dev/javascript/active-consumer-indication/): Learn how multiple consumers can bind to an exclusive queue, but only one client at a time can actively receive messages.
Expand Down
24 changes: 12 additions & 12 deletions src/basic-samples/BasicReplier/BasicReplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var BasicReplier = function (topicName) {

replier.log('\n*** replier to topic "' + replier.topicName + '" is ready to connect ***');

// Establishes connection to Solace message router
// Establishes connection to Solace PubSub+ Event Broker
replier.connect = function () {
if (replier.session !== null) {
replier.log('Already connected and ready to ready to receive requests.');
Expand All @@ -64,12 +64,12 @@ var BasicReplier = function (topicName) {
var pass = document.getElementById('password').value;
var vpn = document.getElementById('message-vpn').value;
if (!hosturl || !username || !pass || !vpn) {
replier.log('Cannot connect: please specify all the Solace message router properties.');
replier.log('Cannot connect: please specify all the Solace PubSub+ Event Broker properties.');
return;
}
replier.log('Connecting to Solace message router using url: ' + hosturl);
replier.log('Connecting to Solace PubSub+ Event Broker using url: ' + hosturl);
replier.log('Client username: ' + username);
replier.log('Solace message router VPN name: ' + vpn);
replier.log('Solace PubSub+ Event Broker VPN name: ' + vpn);
// create session
try {
replier.session = solace.SolclientFactory.createSession({
Expand Down Expand Up @@ -132,7 +132,7 @@ var BasicReplier = function (topicName) {
}
};

// Subscribes to request topic on Solace message router
// Subscribes to request topic on Solace PubSub+ Event Broker
replier.subscribe = function () {
if (replier.session !== null) {
if (replier.subscribed) {
Expand All @@ -151,11 +151,11 @@ var BasicReplier = function (topicName) {
}
}
} else {
replier.log('Cannot subscribe because not connected to Solace message router.');
replier.log('Cannot subscribe because not connected to Solace PubSub+ Event Broker.');
}
};

// Unsubscribes from request topic on Solace message router
// Unsubscribes from request topic on Solace PubSub+ Event Broker
replier.unsubscribe = function () {
if (replier.session !== null) {
if (replier.subscribed) {
Expand All @@ -174,7 +174,7 @@ var BasicReplier = function (topicName) {
replier.log('Cannot unsubscribe because not subscribed to the topic "' + replier.topicName + '"');
}
} else {
replier.log('Cannot unsubscribe because not connected to Solace message router.');
replier.log('Cannot unsubscribe because not connected to Solace PubSub+ Event Broker.');
}
};

Expand All @@ -191,21 +191,21 @@ var BasicReplier = function (topicName) {
replier.log('Replied.');
}
} else {
replier.log('Cannot reply: not connected to Solace message router.');
replier.log('Cannot reply: not connected to Solace PubSub+ Event Broker.');
}
};

// Gracefully disconnects from Solace message router
// Gracefully disconnects from Solace PubSub+ Event Broker
replier.disconnect = function () {
replier.log('Disconnecting from Solace message router...');
replier.log('Disconnecting from Solace PubSub+ Event Broker...');
if (replier.session !== null) {
try {
replier.session.disconnect();
} catch (error) {
replier.log(error.toString());
}
} else {
replier.log('Not connected to Solace message router.');
replier.log('Not connected to Solace PubSub+ Event Broker.');
}
};

Expand Down
16 changes: 8 additions & 8 deletions src/basic-samples/BasicRequestor/BasicRequestor.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var BasicRequestor = function (topicName) {

requestor.log('\n*** requestor to topic "' + requestor.topicName + '" is ready to connect ***');

// Establishes connection to Solace message router
// Establishes connection to Solace PubSub+ Event Broker
requestor.connect = function () {
if (requestor.session !== null) {
requestor.log('Already connected and ready to send requests.');
Expand All @@ -63,12 +63,12 @@ var BasicRequestor = function (topicName) {
var pass = document.getElementById('password').value;
var vpn = document.getElementById('message-vpn').value;
if (!hosturl || !username || !pass || !vpn) {
session.log('Cannot connect: please specify all the Solace message router properties.');
session.log('Cannot connect: please specify all the Solace PubSub+ Event Broker properties.');
return;
}
requestor.log('Connecting to Solace message router using url: ' + hosturl);
requestor.log('Connecting to Solace PubSub+ Event Broker using url: ' + hosturl);
requestor.log('Client username: ' + username);
requestor.log('Solace message router VPN name: ' + vpn);
requestor.log('Solace PubSub+ Event Broker VPN name: ' + vpn);
// create session
try {
requestor.session = solace.SolclientFactory.createSession({
Expand Down Expand Up @@ -135,7 +135,7 @@ var BasicRequestor = function (topicName) {
requestor.log(error.toString());
}
} else {
requestor.log('Cannot send request because not connected to Solace message router.');
requestor.log('Cannot send request because not connected to Solace PubSub+ Event Broker.');
}
};

Expand All @@ -150,17 +150,17 @@ var BasicRequestor = function (topicName) {
requestor.log('Request failure: ' + event.toString());
};

// Gracefully disconnects from Solace message router
// Gracefully disconnects from Solace PubSub+ Event Broker
requestor.disconnect = function () {
requestor.log('Disconnecting from Solace message router...');
requestor.log('Disconnecting from Solace PubSub+ Event Broker...');
if (requestor.session !== null) {
try {
requestor.session.disconnect();
} catch (error) {
requestor.log(error.toString());
}
} else {
requestor.log('Not connected to Solace message router.');
requestor.log('Not connected to Solace PubSub+ Event Broker.');
}
};

Expand Down
16 changes: 8 additions & 8 deletions src/basic-samples/ConfirmedPublish/ConfirmedPublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var QueueProducer = function (queueName) {

producer.log('\n*** Producer to queue "' + producer.queueName + '" is ready to connect ***');

// Establishes connection to Solace message router
// Establishes connection to Solace PubSub+ Event Broker
producer.connect = function () {
if (producer.session !== null) {
producer.log('Already connected and ready to send messages.');
Expand All @@ -63,12 +63,12 @@ var QueueProducer = function (queueName) {
var pass = document.getElementById('password').value;
var vpn = document.getElementById('message-vpn').value;
if (!hosturl || !username || !pass || !vpn) {
producer.log('Cannot connect: please specify all the Solace message router properties.');
producer.log('Cannot connect: please specify all the Solace PubSub+ Event Broker properties.');
return;
}
producer.log('Connecting to Solace message router using url: ' + hosturl);
producer.log('Connecting to Solace PubSub+ Event Broker using url: ' + hosturl);
producer.log('Client username: ' + username);
producer.log('Solace message router VPN name: ' + vpn);
producer.log('Solace PubSub+ Event Broker VPN name: ' + vpn);
// create session
try {
producer.session = solace.SolclientFactory.createSession({
Expand Down Expand Up @@ -127,7 +127,7 @@ var QueueProducer = function (queueName) {
producer.sendMessage(i);
}
} else {
producer.log('Cannot send messages because not connected to Solace message router.');
producer.log('Cannot send messages because not connected to Solace PubSub+ Event Broker.');
}
}

Expand All @@ -152,17 +152,17 @@ var QueueProducer = function (queueName) {
}
};

// Gracefully disconnects from Solace message router
// Gracefully disconnects from Solace PubSub+ Event Broker
producer.disconnect = function () {
producer.log('Disconnecting from Solace message router...');
producer.log('Disconnecting from Solace PubSub+ Event Broker...');
if (producer.session !== null) {
try {
producer.session.disconnect();
} catch (error) {
producer.log(error.toString());
}
} else {
producer.log('Not connected to Solace message router.');
producer.log('Not connected to Solace PubSub+ Event Broker.');
}
};

Expand Down
162 changes: 162 additions & 0 deletions src/basic-samples/GuaranteedPublisher/GuaranteedPublisher.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
Solace Web Messaging API for JavaScript
Publishing Guaranteed messages on a Topic tutorial - Guaranteed publisher
Demonstrates sending persistent messages on a topic
-->

<html lang="en">

<head>
<title>Solace Web Messaging API for JavaScript, Publishing Guaranteed messages on a Topic tutorial - Guaranteed Publisher</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge;" />
<meta charset="utf-8"/>

<link rel="stylesheet" type="text/css" href="../../resources/css/pure.css"></link>
<link rel="stylesheet" type="text/css" href="../../resources/css/samples.css"></link>

<!-- Load Solace Web Messaging API for JavaScript -->
<script src="../../../lib/solclient-debug.js"></script>

<!-- Load the Guaranteed Publisher -->
<script src="GuaranteedPublisher.js"></script>

<!-- Execute the Guaranteed Publish on a topic - Guaranteed Publisher tutorial -->
<script>
var publisher = null;
window.onload = function () {
// Initialize factory with the most recent API defaults
var factoryProps = new solace.SolclientFactoryProperties();
factoryProps.profile = solace.SolclientFactoryProfiles.version10;
solace.SolclientFactory.init(factoryProps);

// enable logging to JavaScript console at WARN level
// NOTICE: works only with "solclientjs-debug.js"
solace.SolclientFactory.setLogLevel(solace.LogLevel.WARN);

// create the publisher, specifying name of the topic
publisher = new GuaranteedPublisher('solace/samples/js/pers');
// assign buttons to the publisher functions
document.getElementById("connect").addEventListener("click", publisher.connect);
document.getElementById("disconnect").addEventListener("click", publisher.disconnect);
document.getElementById("publish").addEventListener("click", publisher.publish);
document.getElementById("clear").addEventListener("click", publisher.clear);
};
function iframeloaded(){
if (publisher) {
publisher.connectToSolace();
}
};
</script>
<style>
.warning {
padding: 5px;
border: 1px solid black;
background-color: #ff8;
}
.ie11 {
/* Hide instructions that only apply to IE11/Edge */
display: none;
}
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
.ie11 {
/* Show instructions in IE11. If you're trying this sample from the local filesystem,
it's easy to miss the prompt at the bottom of the window. */
display: block !important;
}
}
</style>
</head>

<body>
<!-- used to prompt selection of client certificate -->
<iframe id="iframe" src="" onload="iframeloaded()" hidden></iframe>

<div class="banner">
<div class="banner-interior">
<span class="logo">
<a href="http://dev.solace.com/">
<img src="../../resources/images/solace-logo-white.png"/>
</a>
</span>
<div class="banner-heading">
Solace Web Messaging API for JavaScript
</div>
</div>
</div>

<div class="doc-body">
<h2>Persistence with Topics tutorial</h2>
<h3>Guaranteed Publisher</h3>
<!--[if IE]>
<div class="ie9 warning" style="padding: 5px; border: 1px solid black; background-color: #ff8;">
IE9 only: If you are running this sample from the local filesystem, click the "Allow blocked content" button
in the popup below to enable JavaScript.
</div>
<![endif]-->
<div class="ie11 warning">
IE 11 only: If you are running this sample from the local filesystem, click the "Allow blocked content" button
in the popup below to enable JavaScript.
</div>
<form class="pure-form pure-form-aligned">
<fieldset>

<div class="pure-control-group">
<label for="hosturl">Solace router host url</label>
<input id="hosturl" type="text" placeholder="<protocol://host[:port]>">
</div>

<div class="pure-control-group">
<label for="message-vpn">Message-vpn</label>
<input id="message-vpn" type="text" placeholder="Message VPN" value="default">
</div>

<div class="pure-control-group">
<label for="username">Username</label>
<input id="username" type="text" placeholder="Username">
</div>

<div class="pure-control-group">
<label for="password">Password</label>
<input id="password" type="password" placeholder="Password">
</div>

</fieldset>
<p>
<button type="button" class="pure-button pure-button-primary" id="connect">Connect</button>
<button type="button" class="pure-button button-error" id="disconnect">Disconnect</button>
</p>
<p>
<button type="button" class="pure-button pure-button-primary" id="publish">Send Message </button>
<button type="button" class="pure-button pure-button-secondary right" id="clear">Clear</button>
</p>

<textarea id="log" rows="20" cols="90" autofocus></textarea>

</form>

</div>

</body>

</html>

Loading