Sending and receiving PDF via ActiveMQ - spring

I want to send PDFs via camel route to an ActiveMQ queue.
I need to extract these PDFs in another camel route.
Im not able to extract the data from the queue. I also tried it with .marshal().base64(). The Data reaches the Message Broker but I can't extract it.
Following Error will appear:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/util/backoff/BackOff
at org.apache.camel.component.jms.JmsConfiguration.chooseMessageListenerContainerImplementation(JmsConfiguration.java:466)
at org.apache.camel.component.jms.JmsConfiguration.createMessageListenerContainer(JmsConfiguration.java:456).....
Does anybody has an idea?
The Object is org.apache.camel.converter.stream.InputStreamCache when using base64 marshalling.
The Object is org.apache.camel.component.file.GenericFile when just sending the pdf to the queue.
How can I extract the data to get that PDF back?
Here is the Code to deliver two different queues. But I can't extract data even of one.
from("file:src/main/resources/test?noop=true")
.to("jms:queue:PDF")
.marshal().base64()
.to("jms:queue:BASE64_PDF")

this example works well
from("file:src/main/resources/test?noop=true")
.to("jms:queue:PDF");
from("jms:queue:PDF")
.to("file:src/main/resources/testReceive");
it is dependencies problem not Camel, verify that you have spring-core-x.x.x.jar or activemq-all-x.x.jar in the classpath

Related

How to pass error from a processor to PutEmail processor in NiFi

In the below image we can clearly see the error in the Conversion_Batching processor. How can this error be transmitted to PutEmail so that the email recipients can clearly understand the error.
Below is the PutEmail configuration:
But ${error} is not getting the error from the previous processor and I am getting an empty mail with the subject correctly set as expected.
How can I do this?
NiFi currently does not have a feature where we can capture and pass exceptions/errors to the subsequent processors as attribute or flowfile content.
You can configure SiteToSiteBulletinReportingTask which Publishes Bulletin events using the Site To Site protocol. This will give you information such as bulletinsourceid, bulletinsourcename, bulletingroupname, bulletinmessage etc and based on this you can then send out alert notification emails.
Another way is like in your process group Conversion_Batching introduce attribute ${error} and set custom error messages wherever failure happens, and then you can use this attribute value in PutEmail processor, something like below,

How to extract data from AMQP request in JMeter

I have used AMQP Publisher to publish the message in RabbitMQ then I use AMQP Consumer as listener. In the View Results Tree the messages from the queue in shown in the request tab of AMQP Consumer. My question is how to extract data from that request. I tried following the Bean Shell Post Processor but it seems it will only work on Http request. I tried to use JSR223 Post Processor and XPath extractor but it doesn't work as well. Any help?
I wanted to extract the documentId from the request. Here is the Request pattern.
I have already tried following links:
Extracting value from jmeter post request
how to extract value from request in Jmeter
How to extract the values from request input xml in jmeter
The statement that you tried something without sharing the code doesn't make sense
Posting JSON data or code as image is not the best idea
Any reason to extract data from the request? Normally people know everything about the request hence don't require to extract anything from it. Even if they do - they should normally able to store the request data into a JMeter Variable and apply the relevant Post-Processor to it.
Whatever, just in case here is the solution:
Add JSR223 PostProcessor (if you really want to do this using the Post-Processor) as a child of the request
Put the following code into "Script" area:
vars.put('foo', com.jayway.jsonpath.JsonPath.read(sampler.getArguments().getArgument(0).value,'$..documentId')[0])
That's it, you should be able to access the extracted value as ${foo} where required.
References:
JsonPath: Getting Started
Apache Groovy - Why and How You Should Use It

Apache Camel multiple consumers

I've been working with Apache Camel for a while and doing some basic stuff, but now I'm trying to create a route in which I can have multiple "consumers" to the same route, or add a consumer to the route and then process the message.
My idea is to have an Event Driven Consumer which is triggered by an event, and then to read a file from an ftp for example. I was planning to do something like this:
from("direct:processFile")
.from("ftp://localhost:21/folder?fileName=${body.fileName}") // etc.
.log("Start downloading file ${file:name}.")
.unmarshal().bindy(BindyType.Csv, MyFile.class)
.to("bean:fileProcessor")
.log("Downloaded file ${file:name} complete.");
So the idea is I have an event (for example a direct or from a message queue) that has a "fileName" property, and then use the property to download/consume a file with that name from a ftp.
I believe the problem is to have from().from() in the same route, but the problem is if I leave the ftp component inside a "to", then my queue event will be written into a file in the ftp, which is the opposite from what I want; it behaves as a produces instead of a consumer.
Is there any possible way to achieve what I'm trying to do or does it conflict with what Camel is for?
Thanks to the comment from Claus Ibsen I found what I was looking for, the component I needed and wich made it work was the Content Enricher.
Here is the route that worked for me:
from("direct:processFile")
.pollEnrich().simple("ftp://localhost:21/folder?fileName=${body.fileName}")
.log("Start downloading file ${file:name}.")
.unmarshal().bindy(BindyType.Csv, MyFile.class)
.to("bean:fileProcessor")
.log("Downloaded file ${file:name} complete.");
How about something like this ?
.from("direct:processFile")
.transform(simple("${body.fileName}"))
.from("ftp://localhost:21/folder?fileName=${body.fileName}") // etc.
.log("Start downloading file ${file:name}.")
.unmarshal().bindy(BindyType.Csv, MyFile.class)
.to("bean:fileProcessor")
.log("Downloaded file ${file:name} complete.");

React to event "Creating a Node" in Drupal with MuleStudio

I want to build a Flow that when a Node (an article) is created in Drupal, the Title of the Node is published to Facebook as Message. The publishing of Messages to Facebook is no problem, but i have no idea how to get the Event of Creating new Content in a Drupal Installation. Any Suggestions?
From a pure Mule point of view with no changes to Drupal you could poll the index-nodes operation of the Drupal connector http://mulesoft.github.io/drupal-connector/mule/drupal-config.html#index-nodes
<poll frequency="60000">
<drupal:index-nodes startPage="1" pagesize="10">
<drupal:fields>
<drupal:field>nid</drupal:field>
<drupal:field>type</drupal:field>
<drupal:field>title</drupal:field>
</drupal:fields>
</drupal:index-nodes>
</poll>
You would then have to somehow persist a marker such as the last modified date or the last page number in a persistent object-store so it can be read on the next poll so you know which nodes have been processed or which page to start from. If you're using Mule 3.5... then there's a new "watermark" feature for that specific type of functionality. A bit of info on watermarks here: https://www.mulesoft.org/jira/browse/MULE-6861
However a better solution to polling would be to use a message queue such as ActiveMQ or RabbitMQ that Drupal could publish a message to via Stomp for example and Mule can pick up it up via a JMS inbound endpoint or an AMQP inbound endpoint - dependant on what messaging you go with. This way messages are pushed rather than pulled, but does require Drupal customisation.
From the Drupal side of things you could write a simple custom module and implement hook_node_insert(), e.g.
function MYMODULE_node_insert($node) {
if ($node->type == 'article') {
push_article($node->title);
}
}

Store outlook emails generated using Spring JavaMail and Velocity Template

I am generating emails using Spring JavaMail and Velocity Template to send to the customer.I have to store these outgoing Emails into some folder in .MSG format.I did so much research on the web.But not able to find right Java API to do this.And in Spring Java Mail I am not able to find writeTO() method which is in JavaX.mail API.Can some one help me with this issue.
You already found that javax.mail.Part has a writeTo method.
So what you need is a way to "convert" a spring simple mail to an javax.mail
It should work more or less this way:
org.springframework.mail.javamail.MimeMailMessage message
message = new MimeMailMessage(new SmartMimeMessage(getSession(),
getDefaultEncoding(),
getDefaultFileTypeMap()));
yourSimpleMessage.copyTo(message);
javax.mail.internet.MimeMessage result = message.getMimeMessage());
result.writeTo(yourOutputStream);

Resources