How to use ActiveMQ in Meteor? - javascript

I'm building a Meteor application that needs to receive JMS or AMQP messages, process them, and store the results in Meteor's MongoDB. I want this all to happen on the server, not the client.
I read the ActiveMQ AJAX page and that seems like a promising lead, but I don't know how to get it working. I was hoping to just create a new .js file in my project's server folder and put all the code in there, but creating the ActiveMQ AJAX servlet and importing the ActiveMQ javascript files seems to require HTML tags. Also, does AciveMQ need to be running for the servlet to work?
I'm new to web development.

You should take a look at node-amqp (https://www.npmjs.com/package/amqp). It should slip nicely into a meteor project and give you the functionality you are looking for. Once you install it and require it, you should be able to connect to your message server, create a queue, receive messages into the queue, and then it's just up to you to process them and store them to your mongo.

Related

How to connect Java client with node.js server?

I have to build a project that connects a Java application with a node.js server. I've already built the server part, it uses MySQL to store values and can process HTTP requests to return them in JSON format.
The Java app must be able to retrieve data from the server and then process it. The thing is, this application must be receiving information constantly from the server because it will be updating frequently.
Any hints on how to start or documentation you recommend to build this?
Thank you in advance.

Passing NodeJS data to Javascript

I have a web application with a client that receives data from a server. I have the data in NodeJS, but I want to pass the data to a Javascript file. The Javascript file is included in a HTML file, so I can't make the files communicate with eachother.
I am new to NodeJS, so it can be a stupid question, but anyones help is appreciated
This is for a project where I need have a data stream, and I need to pass it into a web application. I tried to pass the data to different page inside my application and then I tried to get that data on that page inside my web application via Javascript, but I couldn't make that work. I'm not even sure if its possible at this point.
Your node server can't communicate with your front-end without a specific way of communication like websocket, you have many other way to communicate with your front-end as node-server, take a look at server send event for example.
By the way your front-end can call your node server more easely with a get request as said #tomerpacific in comment.
For that you have to open a route with your express app. Routing with express
And for call it on a GET request, for that you can use the XMLHttpRequest, and if you have implemented jQuery on your front, you can use Ajax jQuery.

how to connect vue with a raw tcp node server?

the client i am working with has a node js tcp server working with gps trackers through raw tcp. This trackers can not be upgraded to use socket.io or any other library. They simply send raw data.
My work is to upgrade the client and admin communication, currently they login by console using netcat ip port and typing the command they want to execute.
My idea is to use vue since they woule like realtime communication and better ui/ux. I have no idea how to make a raw tcp tranport with vue. any help?
The short answer to this question, is that the browser cannot directly use raw TCP connections. If the browser is your only option you are probably out of luck.
However if you still want to use vue you have a couple of options. You could implement a kind of TCP-socket-bridge. Such as ws-tcp-bridge. You could also write your own middleware server to dispatch events in node.js, using something like the example here.
A third option would be to do something like electron-vue and use its node instance to relay the data to vue with a websocket or socket.io. Here is an example of an express server with electron.
Good luck, and sorry it isn't easier.
Im just thinking above my head here. But what about having maybe a bash script that post to a webhook back and forth. You can post to an endpoint and run a bash script behind cameras, and this same script post back to another webhook that you will be listening to. It wont be fast i believe but it will get the job done. You just have to manage the queue and the webhook listening. Also be sure to limit the webhook origin request to your app only.
Bash easily can save the output of a netcat command, and also this way you isolate the raw tcp communication, giving it an extra layer of security.

Node.js / Express - how to think about client-side database work? (e.g. can't use require())

I've been through a number of Node.js, Express, and other tutorials/posts, and I'm struggling with how to think about connecting to a database on various pages throughout a webapp.
I would like to run a Node.js app (with a server.js file that connects to a database) and then query that database as needed on every page throughout the app.
So if I have an inventory.html page I should be able to have javascript that queries the inventory table and displays various inventory items throughout that html page.
Problem #1. I can't find a way to use mysql on any client-side pages, since javascript can't use node's require() function client-side. As detailed in this StackOverflow post ("require is not defined").
Problem #2. I can't figure out an elegant way to pass a database connection to other pages in my app. A page can send a POST request back to the server.js file, but this really isn't as flexible as I want.
I'm really looking for the modern, preferred way to do a bunch of PHP scripting in my Node app. Can anyone guide me to the right way to do this? Thank you!
You just can't directly call mysql from the client. Even if it worked imagine that anybody could modify the SQL queries and access all your data.
The only way how to do it is this:
js client app ------> js server app -------> mysql
You just must have 2 apps: one running in the user's browser sending requests to the server and the other running on the server answering the requests.

How to give Node.js server a command from php script?

sorry to bother you, but I've been looking for answers and I couldn't find them anywhere... Well i'm a fresh dude in the field of javascript and node.js and here's my problem:
I've created an application based on the tutorial of socket.io - Here's the link to the completed project of their chat example. everything is working as it should, but I would really need to trigger somekind of a command while node server is running... command should be triggered via php script.
The command should trigger an emit event - so every client in our case would see a new message sent via php.
I saw couple of suggestions to do it from another server with php/using cURL. The problem is that I don't know how to fetch POST data sent from php to node.js server.
Any solution to command node with php is more than welcome and again i'm sorry to bother you :)
You can use a bridge to exchange data between NodeJS and PHP. You will need to implement a PHP server that exposes remote procedures and a NodeJS client that calls those remote procedures. You can send any data to the NodeJS application from PHP using these remote procedures.
Here are a few links to get you started:
http://bergie.iki.fi/blog/dnode-make_php_and_node-js_talk_to_each_other/
https://github.com/bergie/dnode-php

Categories