Best Of
TestContainers for Solace PubSub+
I am excited to share an update on Testcontainers for Solace PubSub+ module.
For those who have not worked with Testcontainers, let me help you with the introduction
Testcontainers is an open source framework for providing throwaway, lightweight instances of databases, message brokers, web browsers, or just about anything that can run in a Docker container. It simplifies the process of integrating unit tests with external dependencies by allowing you to declare these dependencies directly in the test code. The containers can be used for a single test and then discarded, ensuring a clean test environment with no configuration clashes or dependency issues.
The importance of Testcontainers for developers lies in its ability to create a more reliable and consistent testing environment. By using testcontainers, developers can easily emulate specific versions of software and other dependencies that the application interacts with.
Solace Testcontainers extends the utility of the general Testcontainers framework by providing a way to spin up Solace PubSub+ event broker instances as part of the test environment. For developers working with event-driven architectures, this is particularly crucial because it allows you to test the interactions of your applications with a fully functional message broker in a controlled environment. This integration ensures that developers can test your messaging infrastructure and event-driven workflows thoroughly, catching potential issues early in the development cycle and significantly reducing the risk of bugs in production environments. This capability is especially important for building robust, scalable, and fault-tolerant distributed systems.
A simple 2-line of code can get you a message broker up and running for testing:
var solaceContainer = new SolaceContainer(DockerImageName.parse("solace/solace-pubsub-standard:latest")); solace.start();
The Solace testcontainer module for Java can be found here Solace PubSub+. For the curious minds that want to look under the hood, the code for this module can be found here. It supports working with the standard protocols supported by Solace broker: AMQP, MQTT, REST, SMF and SMF+SSL.
In conclusion, Testcontainers helps developers gain the ability to automate tests in a consistent and isolated environment, thereby avoiding the "it works on my machine" syndrome and ensuring that their applications are thoroughly tested against a real Solace broker before deployment. This approach not only reduces bugs and deployment risks but also significantly enhances the reliability and scalability of applications in production environments. Hence, leveraging Testcontainers for testing Solace PubSub+ brokers is a prudent choice for developers aiming to build high-quality, event-driven systems.
Would love to hear your take - give it a try and share your feedback!
Re: How to send JSON in Javascript
Hi @TestUserName, welcome to the Community!
If you want to send some JSON, just do: message.setBinaryAttachment(JSON.stringify(obj));
Note that message.setBinaryAttachment(..)
is for just for a plain "raw" binary payload (a BytesMessage). If you want to send a formatted TextMessage in JavaScript, you'd do something like this:
var msg = solace.SolclientFactory.createMessage(); var payloadText = JSON.stringify(obj); msg.setSdtContainer(solace.SDTField.create(solace.SDTFieldType.STRING, payloadText)); msg.setDestination(solace.SolclientFactory.createTopic("hello/world"));
Sending a formatted TextMessage is generally better for actual text strings as it is easier to deal with in other APIs, and you don't have to worry about encoding it correctly… e.g. UTF-8 or whatever, especially if your string contains any weird chars. See this thread for more details on that!
Re: Solace Python API on Mac M1 ?
Just a friendly ping that the latest version of the Python API has been released (v. 1.7.0) with support for Mac M-series processors. It should be slowly rolling out in different places and is already available via PyPI (
)Thanks again for all your patience!
Re: java.lang.ClassCastException: Solace QueueProxy cannot be cast to Weblogic DestinationImpl
UPDATE:
I tried a bunch to get this to work but unfortunately couldn't. So I finally decided to just forego this Message Driven Bean approach and reworked the whole thing by simply implementing a Message Listener in the class file. And whaddya know the simplest solution is the one that works.
This is the modified code:
package main; //<Imports here> public class TopicConsumer implements MessageListener {
private ConnectionFactory connectionFactory;
private Connection connection;
private Session session;
private MessageConsumer messageConsumer;
private final String CONNECTION_FACTORY_JNDI_NAME = "JNDI/J2C/CF";
TopicConsumer() throws InterruptedException {
initialize();
}
@Override
public void onMessage(Message message) {
try {
if (message instanceof TextMessage) {
System.out.printf("TextMessage received: '%s'%n", ((TextMessage) message).getText());
} else {
System.out.println("Message received.");
System.out.printf("Message Content:%n%s%n", SolJmsUtility.dumpMessage(message));
}
// ACK the received message manually because of the set SupportedProperty.SOL_CLIENT_ACKNOWLEDGE above
message.acknowledge();
} catch (JMSException ex) {
System.out.println("Error processing incoming message.");
ex.printStackTrace();
}
}
public void initialize() throws InterruptedException {
try {
Hashtable<String, Object> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
InitialContext initialContext = new InitialContext(env);
connectionFactory = (ConnectionFactory) initialContext.lookup(CONNECTION_FACTORY_JNDI_NAME);
System.out.println("Connection Factory " + connectionFactory + " established");
connection = connectionFactory.createConnection();
System.out.println("Connection " + connection + " created");
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("MyQueue");
messageConsumer = session.createConsumer(queue);
messageConsumer.setMessageListener(this);
connection.start();
System.out.println("Awaiting message...");
} catch (NamingException | JMSException e) {
e.printStackTrace();
}
finally {
try{
connection.stop();
messageConsumer.close();
session.close();
connection.close();
} catch (Exception e) {
System.err.println("Error sending message: " + e.getMessage());
e.printStackTrace();
}
}
} }
Similar to the case with my producer code I directly gave the actual destination name instead of doing a JNDI lookup while creating the Queue. I don't know why i tried to make it extra complicated with the MDB.
Anyways hope this helps anyone else facing the issue. Cheers !!
Quick-and-dirty REST server for RDP testing
Hi there! I thought I'd share a (possibly!) useful snippet of code that you can use to receive REST requests, and respond with a canned body. It's in Node. I don't know Node, so apologies if it's not glamourous code. I was inspired by the "Simple REST Consumer" on this tutorial: https://solace.com/samples/solace-samples-rest-messaging/publish-subscribe/
Update the variable RC_HOST
at the top of the file with your machine's IP address. Don't use localhost
, use the actual IP address. Note, if using WSL2, you'll need to use the "internal" address of the virtual machine. On my Windows machine, I run this from the Ubuntu shell, so my IP address looks like 172.28.123.115
.
And if running the PubSub+ broker locally, inside your RDP Rest Consumer, you can't use "localhost" or "127.0.0.1" when testing with an RDP, because the Solace broker has it's own networking setup. You'll have to specify your actual IP address, or whatever you started the server with.
Anyhow, copy this into a file, and then simply run node NodeServer.js
% cat NodeServer.js var http = require('http'); var RC_PORT = 9090; //var RC_HOST = '127.0.0.1'; // only works from browser, not RDP //var RC_HOST = '10.1.1.245'; // home var RC_HOST = '192.168.42.194'; // office LAN http.createServer(function (req, res) { let date_ob = new Date(); var dateStr = date_ob.getHours()+':'+date_ob.getMinutes()+':'+date_ob.getSeconds(); //console.log(req); // all the details of this request console.log('Received message: ' + req.method + " " + req.url + ' at ' + dateStr); Object.keys(req.headers).forEach(function(key) { //if (!key.startsWith('solace')) return; var val = req.headers[key]; console.log(' HEAD:' + key + ' = ' + val); }); let body = []; req.on('data', (chunk) => { body.push(chunk); }).on('end', () => { body = Buffer.concat(body).toString(); // at this point, `body` has the entire request body stored in it as a string console.log(' BODY: '+ body); }); // RESPONSE TIME! //res.writeHead(200); // bytes message res.writeHead(200, { 'Content-Type': 'text/plain' }); // text message res.write("Hello world from Aaron's test HTTP server!"); res.end(); //console.log(res); }).listen(RC_PORT,RC_HOST); // good to go! console.log('Server running at http://'+RC_HOST+':'+RC_PORT+'/');
When you send a request, it will dump stuff out to the console. Here's a quick test from Chrome, loading http://192.168.42.194:9090/hello/world
:
Server running at http://192.168.42.194:9090/ Received message: GET /hello/world at 15:0:48 HEAD:host = 192.168.42.194:9090 HEAD:connection = keep-alive HEAD:upgrade-insecure-requests = 1 HEAD:user-agent = Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 HEAD:accept = text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 HEAD:accept-encoding = gzip, deflate HEAD:accept-language = en-GB,en-US;q=0.9,en;q=0.8 BODY:
Have fun playing with RDPs and Solace+REST!
New Graphical Designer in Event Portal
Hi all,
📣 We are pleased to announce the availability of the new graphical designer in Event Portal. This feature is being delivered in phases, with this first phase providing a graphical view of the event driven architecture for each of your application domains.
⭐️ The graph displays the latest, non-retired version of each application and event in the application domain, and shows the intended pub/sub relationships between them, as well as the relationships with events and apps in other application domains. As you drag objects around in the graph to customize the view, if you have Editor level access or higher, the changes are automatically saved and can be viewed by other users who can access the app domain. You can also double-click on an application or event icon in the graph to view or edit the details of the object.
⭐️ Check out this video for a demo of this new feature and what we are planning to add to it next.
✅ Stay tuned for those upcoming enhancements!
Introductions Thread - New to the community? Start here!
Intro
Hi all, if you've joined recently you may have seen a welcome message from me in your inbox but I figured a great way to get to know folks here would be an intro thread. As we share Solace related knowledge and learn from each other, let's get to know each other!
Name or handle
(only share what you're comfortable with of course)
In real life I'm Trish Mermuys and you can find me on twitter @mermuys and LinkedIn if you want to connect with me there.
Location
Where in the world is...
I'm in Ottawa, Canada. Right now I'm working from home but normally I'm at Solace's headquarters here in Ottawa.
Job
I'm currently the Developer Content and Community Manager here at Solace. My job is to help make this community a thriving place where you can find other people who are as passionate, interested, and curious about Solace, PubSub+, Event Portal, and really anything related to event driven architecture.
For fun
Tell us about the fun story about your experience with Solace
For me it's not directly related to Solace software or the broker, but starting a new job in the midst of a pandemic. I had worked remotely before, but it was temporary (six months) and with a team of people that I already knew quite well and had great rapport with. I started with Solace in May when everything was pretty much shut down here in Ottawa. So I didn't get to meet any of my coworkers in person until last week. We just had restaurant outdoor patios open recently so I was able to join @hong and @Tamimi for some drinks and food and finally see them in real life! It was a great moment to get to know them even better, plus the beer tasted really good!
Now it's your turn! Comment below👇 and tell us a bit about yourself!
New blog post for developers | The Importance of Event Governance in EDA
Distributed Tracing is now Generally Available!
I'm thrilled to announce that Distributed Tracing is now generally available for all customers and prospects. The recent release of PubSub+ 10.2.0 included distributed tracing!
Thanks to all the customers who tried out our early access release of distributed tracing! Our Early Access release of distributed tracing is now complete! We had a record-breaking number of customers asking for this early access release! Thanks again!
If you would like to continue to experience distributed tracing for free, you still can! Distributed tracing in demo mode is available for current and trial customers in 10.2.0! Check it out!
Solace Distributed Tracing is an amazing new capability that pulls back the curtain and lets you understand on an event-by-event basis what is happening to your events as they traverse through the event mesh. It unites the event mesh with the observability tools used today with application performance monitoring and HTTP/REST messaging! Ultimately, it will provide full visibility of your events as they traverse clients & the event mesh for debugging, troubleshooting, event mesh analytics, performance analysis, audit, governance, and non-repudiation among other use cases. We expect to deliver wave upon wave of new distributed tracing capability over the coming releases.
Speaking of which, keep your eyes out for the upcoming early access release of Distributed Tracing with Context Propagation! This time it will be available on Solace Cloud too! Coming soon!
Keep handling those events,
Rob Tomkins
Core Product Manager
New blog post for developers | PubSub+ Event Portal Application for Confluence
Solace PubSub+ Event Portal offers a range of features and capabilities that support the management and governance of event-driven architecture (EDA) throughout the software development lifecycle (SDLC). From event discovery and documentation to versioning, collaboration, and integration with development tools with its Cloud REST APIs, Event Portal helps teams streamline the development and maintenance of EDA, ensuring consistency and effective communication across the organization.
Leave your comments below.