Trouble receiving multiple emails with camel aggregator - java

I'm truly not sure how to word this correctly, but I'll try my best.
I want to send n emails to n recipients via a camel route and have those n recipients send approvals to the sender, which is done by using the world 'approve' in the subject, at which point, I'd trigger a process.
The first half of this task is done, as sending emails is a relatively simple task in Camel. Receiving is as well. My problem lies in the fact that I'd like to wait on these n emails to be received before continuing.
I'm using this code to attempt to do the latter half.
from("imaps://imap.gmail.com?username=emailaddress#gmail.com&" +
"password=RAW(password)&searchTerm.subject=approve")
.aggregate(header("*"), new UseLatestAggregationStrategy())
.completionSize(2)
.process(myProcess);
I know this code won't do exactly what I'm asking for, but it's what I'm working with for now. I'm getting this error when I drop the .jar into ServiceMix
org.apache.camel.CamelExchangeException: Invalid correlation key. Exchange[MailMessage:
I've tried looking up the error, but I haven't gotten much that's helpful. It's fairly obvious it's from either the header or the aggregation strategy, but again, I have yet to find anything useful for my situation.
Is there a better way to do this? I feel like my problems are coming from not completely understanding the nuances of camel, so there may very well be an easier/better way to achieve this. If not, what am I missing?
I apologize if I've left anything useful out. Feel free to ask questions.

You can use a constant as the correlation key if you want any message to be grouped together, for example:
.aggregate(constant(true), new UseLatestAggregationStrategy())

Related

How to receive a multipart message in ZMQ using Java?

As simple as this operation seems I can't find any documentation regarding how to receive a multipart message using ZMQ (Jeromq). I checked The Guide but it only contains C code with this info and it seems that I'm supposed to receive messages the same way no matter what kind of message I'm receiving.
In reality what happens is that I receive the multipart message in two messages with this code:
while (running.get()) {
items.poll();
if (items.pollin(0)) {
ByteArray message = receiver.recv(0);
System.out.println("Received " + String(message, Charset.forName("UTF-8")));
}
}
The "Received" part will get printed twice if I send a multipart message like this:
publisher.sendMore(message.key);
publisher.send(objectMapper.writeValueAsString(message.data));
What am I doing wrong?
Edit: I know there is a language selector below the examples but this particular problem is not present in any of the examples only explained inline with C code.
Edit
I tried to explore the API and found the hasReceiveMore() method. I tried using it, but it didn't work, I ended up with an infinite loop with this code:
List<String> parts = new ArrayList<>();
while(receiver.hasReceiveMore()) {
parts.add(receiver.recvStr());
}
Q : "What am I doing wrong?"
Your code has to actively assume each message to might have been composed as a multipart-message (Zero-Warranties in this, the less a-priori) and actively check for the presence of the ZMQ_RECVMORE flag, after each subsequent .recv()-method call, until the .getsockopt( ZMQ_RECVMORE )-method says otherwise.
JeroMQ might have translated this published native-API into some other utlity methods, so best re-read the JeroMQ-source code to find, where this native-API multipart-message handling-"protocol" gets wrapped into the JeroMQ-tooling.
EPILOGUE : Verba docent, Exempla trahunt...Having helped more than 1.3 M Community members and countless anonymous site visitors, I got punished and censored for helping.Censorship of deleting comments continues. The spirit of StackOverflow turns to digital totalitarianism. Delete, delete and punish those, who keep thinking and present help and advice to those, who ask for a sponsored help...-------------------------------------Let's review the facts:-----"I couldn't find any docs regarding how I should receive the parts, but I tried something that looks like what you mentioned...it didn't work either. – Adam Arold 20 hours ago"Either of not finding "any docs" or a "not working" (another not published, reproducible MCVE) were my fault or omission, were they?( my answer to these false claims was administratively deleted a few minutes after being posted... Self-explanatory )-----"This is not an answer and it doesn't contain a solution. I'm not sure why you're surprised. What you cited is the C API that has nothing to do with the JeroMQ API. In the end the solution was that I have to recv before I try to check the RECVMORE flag. This was not in your answer. Alternatively ZMsg can be used. – Adam Arold 11 hours ago"ANALYSIS OF THE CLAIMS :Sentence #1. :"This is not an answer and it doesn't contain a solution."This IS an answer, in spite of the "claim". It contains several important pieces of information, that she/he/anyone would otherwise have to try to seek for hours (days or weeks?) to later study and conceptually well comprehend architecture-wise so as not to make any ill-formulated code-design(s) or get principally trapped into one's own, misconcepted, decisions, if not having been advised and warned about thses possible shortcommings I've personally met ( and help others not to repeat ) throughout my last 13+ years spent with fabulous Martin Sustrik's masterpiece - the ZeroMQ, since v2.1+. So this "claim" is both wrong and unsupported by facts. A minor "claim" that the answer did not contain a solution is absurd, StackOverflow Community members are neither an employee to shout at, the less we bear a commitment to program a code that will snap and fit all the needs of the (unpublished) use-case.Sentence #2 :(an expressed feeling)- rather skipped as it is more a case of insult than a fair argument, isn't it?Sentence #3 :"What you cited is the C API that has nothing to do with the JeroMQ API."Oh sure, YES , the C API ( and the ZeroMQ-RFC docs on mandatory "wire-line" protocols properties that any peer-implementation has to obey... ) is the starting point and a cardinal reference in all of this. And NO , both the published ZeroMQ RFC-documents and the API are the rock-solid reference for anyone to start with, so as to best understand, how the internal engines and all the mandatory "wire-line" properties obeying protocol pumps are working (and must be working), so as to declare themselves to retain the ZeroMQ-compatibility. The JeroMQ-authors did their work based on these documented properties, didn't they? If they did not or if they "cut some corners" on doing that, the story is lost and was not my fault they did not meet and/or cover all the ZMTP/ZeroMQ-RFC/API properties & requirements, was it? That said, any wrapper/binding, including any version of the JeroMQ must also conform to these inner working rules, which is sufficiently self-documented & demonstrated, if nowhere else, in the JeroMQ source-code (Which warning was also the part of the Answer provided, wasn't it?), if it aspires to be a ZeroMQ-compatible tool. Again, should your current (used) JeroMQ-implementation misses to meet a well documented JeroMQ-API documentation you would like to use & read through (to find both the description and examples of code for the use-cases), which was claimed it did not or that the will to seek and find any such (source-coded) information, it is not the Community sponsoring member to punish for the lack of both the former, the more the latter.Sentence 4. + 5. :This needs to get highlighted:"In the end the solution was that I have to recv before I try to check the RECVMORE flag. This was not in your answer."First of all, it WAS in the Answer - the very first sentence:"...code has to actively assume each message to might have been composed as a multipart-message (Zero-Warranties in this, the less a-priori) and actively check for the presence of the ZMQ_RECVMORE flag, after each subsequent .recv()-method call, until the .getsockopt( ZMQ_RECVMORE )-method says otherwise."My generation grew up in a deep belief, that if we've made an error or 've made a poor decision, based on an unsupported assumption, we never punish anyone else, for (us) having made an error of a bad decision. Surprisingly, not working here. Why would anyone ever punish a person, who reached out and came to help you solve your problem and sponsored your personal need to get a step further? No one will if the culture to ask for a sponsored help and punish anyone who did would grow further. Isn't this called an arrogant or dictator-alike style of person to person behaviour? Be it the former or latter, it is neither fair, the less a style to be promoted the less rewarded as a Community preferred behaviour. The "argument" per se is empty, void - Not having called a .recv()-method, nothing gets ever from inside the ZeroMQ-API abstract horizon, the less an indication, promised to learn by .getsockopt()-method's use on getting a RECVMORE-flag ( sure, after some .recv() has been confirmed to have gotten a substance --The-Message-- That is both elementary and does not need to "include" it in any text about ZeroMQ/JeroMQ messaging as it is self-explanatory - Would anyone claim that it was unfair not to explain that asking for an email-attachment makes no sense if there were no email delivered so far? No one fair ever would. So, the Answer did the very opposite - it did warn about this, that for every .recv()-ed message, professional designer ought always assume a { 0+ }-RECVMORE-flagged multi-part message components, that follow the first one .recv()-ed and need to get dug out of the API.The last sentence :"Alternatively ZMsg can be used."This claim remains an undecidable problem, as the O/P contains zero information about a version. Native ZeroMQ API has evolved since its premiere release via v2.0-v2.1-..-v2.11, via v3.0-v3.1-v3.2, refactored and extended via v4.0-v4.1-v4.2-v4.3 and still counting, and a "claimed" Zmsg-abstraction is sure not to be present in earlier implementations, so the version number is cardinal on this ( also being a part of the StackOverflow best practices for how to ask good questions with a problem-reproducing MCVE / MWE code and all relevant details, the version number being one part of that, isn't it? ).

How to connect java and Adf.ly?

Is there any way in java to make code: Example if someone clicks on skipAd on adf.ly link Int will increase. Example 2: I click the button, it will take me to a adfly link. and when i click skipAd on adf.ly: in the app int will increase for 1(int++).
Is there any way to do that?
First of: StackOverflow hates it when people come here showing that they have taken zero effort to find a solution for the problem.
Secondly:
Your question is very unspecific.
Are you and your friend on the same network? If so, you might want to consider using ARP-Poisoning in order to inject custom JavaScript into the webpage that will function as an EventListener. Obviously this will only work if he is visiting AdFly via an HTTP connection and since Adfly-Links are generated with an HTTPS prefix, you will rarely find people using HTTP (despite the fact that they still don't enforce HTTPS, grumpf).
There are probably tons of other solutions but they will all involve tinkering with his/your webtraffic. And no offense, but I feel like you should probably learn some more Java before taking on such a big task.
More than in 'java' it would be easier to do it in 'JavaScript'. You'll have to monitor the onClick event of that SkipAd button and then you can increase your counter.
I advise you to make your question even more clearer in why-you-have-to-do-it department to avoid down votes

Detecting successful channel join in IRC with Java

A friend and I (well a friend w/ me looking over the code to find any logical inconsistencies) are trying to write an IRC bot in Java mostly from scratch (that is, not using egg drop or other popular starting points). It's rather easy to detect a successful server join (socket.isConnected()), but I'm trying to figure out a way to detect a successful channel join. Basically, instead of just assuming that the join was successful, I want to be able to read from the server if the nick is moderated or banned or something else which prevents channel joining. Thanks!
Basically I want to be able to print out "Channel __ joined" if successful or "Channel ___ join failed" if the join wasn't successful. Is there anyway to do this? Thanks!
Edit: Upon further research, I'm now interested in learning how to decipher server message codes, specifically the format in which they're sent back to the client. Thanks!
Try reading through the RFC, particularly the JOIN command and the numeric replies. The Messages section explains the basics of sending messages back and forth. You should probably try to understand a protocol before you try to implement it though ;)

How to send a broadcast message with SmackAPI?

We're developing special devices that uses XMPP to talk to each other. A new API i am developing now, should talk to these devices too. The problem i am facing - all these devices are building little groups - for each customer we have... so we will have a chat-room for each group of devices, or, for each of our customer with his bunch of devices ;)
But now.. the api should be able to talk to every device that is connected. I don't need a real broadcast-mechanism - in the end, i will send a message only to one specific device..
But i don't want to login to each chat-room either - running a product with over 40k customers and much more devices, will end in a funny api, that is opening over 40k chat-rooms at startup... even if don't tried this yet, i can't imagine that an app like this will run well... even though we can have millions of customers in a few years.. i don't like solutions that will grow linear with the amount of customers, if you know what i mean :/
Now, basically i'm thinking of a solution, where i just can use the basic XMPPConnection to do my stuff.
MyCustomMessage msg = new MyCustomMessage();
msg.setTo("*"); // don't know what to address, i want to send it to "all"
msg.setFrom("ThatAPI"); // just a string telling that is sent from my java api ;)
msg.setEvent(event); // stuff that is coming through the parameters of the method where this code is inside
msg.setCustomStanza(data); // same here
connection.sendPacket(msg); // my try to send it to all till now..
Somewhere in the Ignite Realtime Forums i have read of one guy who "solved" it, but everything he says is "it's working now, i push my message through the sendPacket of Connection"... ok nice, my attempt of this seems not to work :(
Any better ideas/real implementations how this will work fine?
Basically i start to think that XMPP will not be the best technology to achieve something like this at all - i wish i could have a real/basic socket-implementation where something like this would be piece of cake.. But i can't choose - the third-party-system has implemented XMPP already... not enough time to change all of this... Just if you're wondering why we try this on XMPP..
You seem to have some conflicting requirements in that you want to send to all devices now, but only 1 specific device later. Are both models required at the same time, or do you plan on switching? How either is done would be different solutions.
As for your current approach, I think pubsub would make more sense than your chatroom approach, as that is oriented to generic message passing to subscribers.
You could set up a pubsub node per customer to send messages to all
of their devices.
As for a broadcast to all, you can make all devices
subscribe to a single pubsub node.
Thus you control broadcast and group messages by sending to the appropriate pubsub node.
For sending to a specific device, that is just a sendPacket to the specific entity, nothing really special there.

Where to start for my java program (Using the folder names to get info from IMDB)

I finished first year comp sci. And i want to spend some time working on the things they have taught us in the first year (lot of java and a bit of C)...
Anyways as a project, i wanted to do something i need, and what i need is a program to run through my movie folder and get the ratings and some basic info from IMDB...
I'm not sure where to start, i think i can handle the parts about reading the folder names, getting rid of the junk from the name to get the actual name and stuff.. Also i can handle the GUI but i don't know how i can talk to IMDB... what steps should i take to complete this project. I have about a month before school starts and i want to finish it before then...Thanks for all the input
EDIT:
Also can you guys tell me what i should start with and then move on to what? As in should i start with the GUI first or have the code that reads in the folder names and filters the names... I only wrote one program as an assignment in school and it was basically outlined step by step so i just wanna know what i should start with
You've made a very good start by decomposing the problem, identifying the kind of components you need and focusing on (an important) one that you don't know how to do.
The IMDB API is documented here and you can see that it amounts to sending simple HTTP requests with some paramters and getting back some formatted data, possibly as a JSON string.
You will find libraries to help with doing those two things. Even if there are public domain wrappers for accessing IMDB I'd recommend attempting to use general purpose HTTP and JSON libraries - that's probably a better educational exercise.
I'm the author of the IMDB API you are dicussing ;) I limit requests to 30 per hour to stop people hammering. I have yet to have a legitimate reason to perform more requests than that. My suggestion to anyone is to write a batch script to perform 1 request every 2minutes and then leave it going for a few hours overnight. Then you only have to perform a request on demand whenever you add a new movie.

Categories

Resources