Moving messages between queues - java

Is there a IBM MQ JAVA API to move messages from one queue to another?
I am able to browse messages from the queue and put messages as well using Java APIs. But I want to move a message from one queue to another. Could you please give a sample code if there is any?
Or do we have to dequeue the message from queue1 and then put the message into queue2 for moving the messages?

You need to GET from queue 1 and then do a PUT on queue 2. If you just browse then there are chances that before yoy GET it out of queue 1, the consumer have already consumed it using GET. You can find sample code for many scenarios on this website.

I have faced the same issue and after lot of frustrating hours i have done it using tool "MQJExplorer_v0.16". Using this tool you can export/import all the messages(or a single message) from one queue to another queue.
If you are facing any issues while installation. Please make sure you are using the correct jdk version (I faced the same issue). You can check the java version in the MetaInf file of one of the downloaded artifacts, make sure you have the same jdk or newer version on your localmachine and just set the JAVA_HOME in the environment variables.

Related

Notify a separate JVM to preform a task

So I am making a program that will only run one instance at a time and am doing so by using this solution
However now I would like to make it so that if the user trys to launch another instance it will consume that attempt and notify the current instance to show its gui.
Currently I am thinking about doing this by the use of a file. Upon the launching of a second instance, a file called show.stage will be created. When the other instance detects that file it will show its gui and delete the file.
I know this works but I was wondering if there was a more graceful way to do this.
Could I some how set a environment flag that the other instance could check for or maybe notify it via a socket listener, although those seem to be discouraged by others. I get the feeling creating the file will be the easiest and most robust way but I am open to any suggestions
This program will be running on normal windows.
If you don't want to use a lock file (which I think is a perfectly good solution), you can use sockets.
Have your application create a socket server and listen at some port in localhost. If it fails to listen, it would mean that someone else is listening to that port already - most likely, another instance of your app. You can even connect to that port and send messages to notify the primary instance that a second instance tried to be spawned.
The caveat is that if another app legitimately uses that port your app would never be able to run - but I find that very unlikely to happen.
There are many ways to go about this:
as you already figured, the file system can be used as communication channel between two jvms. But that only works for jvms running on the same server.
thus the already suggested socket solution enables you to (later) apply the same solution to a distributed environment. The downside is that you have to implement a protocol on a very low level.
in the past, people often turned to message bus solutions (think ActiveMQ for example)
in 2018, the other alternative would be to implement a simple restful API, using jaxrs and jersey for example.
As said: the effort you want to put into this depends on your requirements. How long will it be used? What are the odds that your solution will grow and has to scale to more than one server?!
try to use pidfile as lock and process single like kill 9 as communication tool

Codename One - Can`t make simple build

Ive try to send basic Android Build as tutorial says but Im getting this error. PS: I never would made any build before, and every day this message persists. (I`m using the Free account).
build-for-android-device:
[codeNameOne] You have a build in progress within the queue. Only one build may be active at a time
Someone may help me?
Looking at our support logs I think this was an issue that was resolved by a support engineer. The issue was related to an email account containing a + sign in the address specifically name+name#domain.com
Since our system uses emails to identify users this caused some issues and failed to show builds that went thru. So there was a build stuck in queue that never got built...
Restart your IDE, operation system.
You have queue of build right now.

Java Camel RouteBuilder picks up file before copying is complete

I am using Ubuntu (in case it will make a difference) and I am trying use Camel to send files to processor from one folder. But the problem is that when I am saving this file in the folder (takes about 5-10 seconds) Camel picks it up straight away.
To simulate the process I am using gedit with txt file with ~500k rows so it will take some time to save.
I have tried adding options:
from("file:src/Data/new/?readLock=changed&readLockMinAge=3m")
I have tried using
.filter(header("CamelFileLastModified").isGreaterThan(new Date(System.currentTimeMillis()-120000))) to give 2 minute delay.
Nothing seems to influence its behaviour, it picks it up straight away, throws an exception because of some checks while processing file and moves it to the Error folder.
I know there is an issue with FTP file transfers which I will have to face later on, but I can not even get it working on local file system.
Any help will be appreciated!
SOLVED
from("file:src/Data/new/?readLock=changed&readLockMinAge=3m")
Parameters actually work as they should. I was using Jetty to run the project and I should have done whole project clean/install after any amendments.
I had to amend parameters a bit to:
from("file:src/Data/new/?readLock=changed&readLockTimeout=65000&readLockMinAge=1m")
because it was complaining that readLockTimeout should be more than readLockCheckInterval + readLockMinAge.
Have a look into the documentation:
Avoid reading files currently being written by another application
Beware the JDK File IO API is a bit limited in detecting whether
another application is currently writing/copying a file. And the
implementation can be different depending on OS platform as well. This
could lead to that Camel thinks the file is not locked by another
process and start consuming it. Therefore you have to do you own
investigation what suites your environment. To help with this Camel
provides different readLock options and doneFileName option that you
can use. See also the section Consuming files from folders where
others drop files directly.
So I think the doneFileName option will solve your problem.

Truncation of web socket chunk while uploading a file

I have tried searching for this strange issue I am facing but could not find anything on web.
Following is what I am trying to do.
Upload File from User browser to Play server running on some different environment
Following is the issue I am facing.
The chunk is getting truncated before reaching to Play server
Observations:
Chunk is created at client side properly from java script and websocket.send() is passing proper chunk to Play.
On Play server, the chunk is coming as a String event object which is truncated.
Very strange thing about this problem is This is happening only from some machines/networks, for all others it is working fine
When tried with different chunk size, it has been observed that for smaller chunks many of initial chunks gets received properly and later one fails
We have tried bypassing Firewalls and Proxies as well on some network to check what happens if there are no such restrictions, but it is still failing
Please give your inputs which can help me debug this and fix this. Any additional things you want I can provide, not pasting code as it is working on majority of machines and networks but failing on a few, so it does not seem to be a code issue
PS. This question can have many answers based on people's views, to all SO users, I just need help on what could be the thing which can go wrong, so please do not flag this as inappropriate
I have figured it out, the issue was with latest update of google chrome. I downloaded the chrome from here (Version 37) and it started working fine.
I came to know after a period of time that this issue was because of the implementation changes in chrome V38 for multiple frames for single message, initially it was getting transferred in a single frame so ultimately the implementation from your server side also need to be changed in order to handling the same.
I was using older version of Play framework which wasn't having this multiple frame handling implementation so it was breaking.
After updating Play to 2.2.3 it started working properly as they have implemented multiframe handling in that version. Some useful links below
Issue With Latest Chrome
Play Changelog
Changes for Continuation frame handling for WebSockets in Play 2.2.3

Queuing requests to have just a single user "working"

Basically I'm trying to build a Java WebApp that will interface an Arduino. Due to this "phisical" limitation I will have just one user at the time working with the microcontroller.
I would like to create a queue with all the requests and set a limit (i.e. 20 seconds) and then go with the next user. There will be probably in the future the option to have two users connected to "interact" each other.
How can I implement this infrastructure? JMS? Other ways?
I've used other mqs as Kestrel but just with "strings", and I've no clue on how to use it in my case. : /
(I will probably use JBoss if this is relevant, or helpful)
Thanks in advance!
There is an RXTX Java library that comes with Arduno and I would suggest to use that for Arduno interface.

Categories