Never too young to start messaging, never too old to play!
Use the Scratch extension to write an MQ program that sends messages using the IBM MQ REST API
Messaging is vital to how enterprises work because it underpins many essential tasks that a business has to deal with, such as employee records, customer transactions, or banking. Without messaging, it would be nearly impossible to do these simple tasks safely and securely.
In spite of messaging being so fundamental to the world of computing, it receives little coverage in the classroom, even at the university level. As a result, messaging can seem unfamiliar and inaccessible.
Ever wished messaging software could be easy to use? In the IBM MQ Developer Experience team, we challenged ourselves to make MQ simple enough to use that our team lead’s nine-and-a-half-year-old could write an MQ program. To make this possible, we wrote an extension for Scratch that uses the IBM MQ REST API to send messages. What we ended up with was a great tool to help people to easily understand messaging in general and IBM MQ in particular.
Scratch is a programming language developed by the Lifelong Kindergarten Group at MIT, designed to help 8- to 16-year-olds understand programming concepts and write their own applications. It uses click-and-drag blocks, which can be joined together to visualize the flow of a program. MIT also manages ScratchX, a website that allows Scratch users to run their own extensions.
We’ve made an IBM MQ extension for ScratchX, which can be found here. The extension contains blocks to put and get messages and also functionality to use the request/response messaging pattern.
What does the IBM MQ extension for ScratchX look like?
Let’s have a look. The extension puts MQ blocks into ScratchX, ready to connect to an MQ queue manager. The put block looks like this:
This block lets you specify the IBM MQ connection variables. At the end of the block, you can enter the message you want to send.
The get block looks similar, but it also comes in the form of a reporter block, which allows the message payload to be stored in Scratch variables, like so:
Request blocks include a correlation ID which links a request and its response together. We might want to do this if we were building a conversational program like a cinema ticket booking app. Many people can request to buy tickets at once, but we must ensure the responses are sent back to the original requestor. For the response blocks, we also let you specify the ‘reply-to’ queue. The two blocks look like this:
These blocks work together to make fully-fledged Scratch programs that can integrate with other apps.
What did we make with it?
The image below shows a game that we made where the player has to match a sequence of colors. Scratch is used to put colors onto a queue (first set of blocks). The colors are sent to a $5 Raspberry Pi Zero, which reads the messages and uses them to control a series of colored lights for the game. Scratch gets the scores and displays them on the screen (second set of blocks).
The game looks like this in action:
Why did we make it?
Our ScratchX plugin is designed to give people a route into messaging and demonstrate just how simple MQ can be to use. It makes it easy to give demonstrations and build games so even young children can see the value.
We’ve had some great feedback from developers and teachers at conferences like Devoxx and CogX, and from students attending events at universities. MQ admins and technical experts at the 2019 IBM Hursley European Summit had a lot of fun with the demo too.
Give it a try!
Ready to give it a go? We’d love to hear how you get on. The IBM MQ ScratchX extension code is open source, so you’re welcome to submit your own projects and pull requests too!
So, what are you waiting for? Get hold of the IBM MQ ScratchX extension and start sending messages with MQ today!
Scratch and the Scratch logos are the intellectual property of the Lifelong Kindergarten Group at the Massachusetts Institute of Technology (MIT). Scratch (and MIT) in no way endorses this open source extension. We do hope they like it, though.