I want to test the scenarios of sending message to AWS SQS from Jmeter. But i dont find any relevant procedure to do it. I came to know about awsmaster plugin but after installing it, it doesnot get installed(seems like a corrupted version)
I am trying with Custom code but there also, the attribute builder() of "sqs client" shows a warning as "This static method of interface SqsClient can only be accessed as SqsClient.builder"
So, can someone please guide how to send messages to SQS queue using Jmeter and the steps.Thanks
If you're willing to copy and paste the code to initialize the SqsClient you can take a look at AWS Java SDK Examples repository:
SqsClient sqsClient = SqsClient.builder()
.region(Region.US_WEST_2)
.credentialsProvider(ProfileCredentialsProvider.create())
.build();
Then you can send the message like it's described here:
CreateQueueRequest request = CreateQueueRequest.builder()
.queueName(queueName)
.build();
sqsClient.createQueue(request);
GetQueueUrlRequest getQueueRequest = GetQueueUrlRequest.builder()
.queueName(queueName)
.build();
String queueUrl = sqsClient.getQueueUrl(getQueueRequest).queueUrl();
SendMessageRequest sendMsgRequest = SendMessageRequest.builder()
.queueUrl(queueUrl)
.messageBody(message)
.delaySeconds(5)
.build();
sqsClient.sendMessage(sendMsgRequest);
The code can be placed in i.e. JSR223 Sampler, use Groovy as the scripting language.
Make sure to add necessary import statements, copy AWS Java SDK with all its dependencies to JMeter classpath and restart JMeter to pick up the jars.
Related
I have JMeter 5.2.1 installed in my system.
When I try to execute below code i am getting this error.
Response message:javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during class generation: java.lang.NoClassDefFoundError: Unable to load class com.azure.messaging.eventhubs.EventDataBatch due to missing dependency org/apache/qpid/proton/amqp/messaging/Section
Code:
import com.azure.messaging.eventhubs.*
final String connectionString = 'EVENT HUBS NAMESPACE CONNECTION STRING'
final String eventHubName = 'EVENT HUB NAME'
// create a producer using the namespace connection string and event hub name
EventHubProducerClient producer = new EventHubClientBuilder()
.connectionString(connectionString, eventHubName)
.buildProducerClient()
// prepare a batch of events to send to the event hub
EventDataBatch batch = producer.createBatch()
batch.tryAdd(new EventData('Fifth event'))
// send the batch of events to the event hub
producer.send(batch)
// close the producer
producer.close()
Below are dependent libraries that i have it in LIB folder. Can you please let me know if i am missing any dependency or using wrong version
dependency.
amqp-client-5.7.1.jar
azure-core-1.13.0.jar
azure-core-amqp-2.0.2.jar
azure-core-test-1.5.3.jar
azure-eventhubs-3.2.2.jar
azure-identity-1.2.3.jar
azure-messaging-eventhubs-5.5.0.jar
jackson-annotations-2.9.0.jar
jackson-core-2.9.9.jar
jackson-databind-2.9.9.jar
jackson-dataformat-xml-2.9.9.jar
jackson-datatype-jsr310-2.9.9.jar
jackson-module-jaxb-annotations-2.9.9.jar
junit-jupiter-api-5.6.3.jar
junit-jupiter-engine-5.6.3.jar
junit-jupiter-params-5.6.3.jar
mockito-core-3.3.3.jar
proton-j-0.31.0.jar
qpid-proton-j-extensions-1.2.1.jar
reactive-streams-1.0.3.jar
reactor-core-3.3.12.RELEASE
reactor-test-3.3.12.RELEASE
slf4j-api-1.7.28
stax2-api-3.1.4
woodstox-core-5.1.0
The org/apache/qpid/proton/amqp/messaging/Section lives in proton-j-0.33.4.jar
I don't know where did you get your proton-j-0.31.0.jar from, my expectation is that you should stick to Microsoft Azure Client Library For Event Hubs ยป 5.5.0 and use dependency management system like Maven or Ivy in order to obtain the library with all its dependencies including the transitive ones.
Once you obtain them - copy all the .jar files to "lib" folder of your JMeter installation (or other location on JMeter Classpath) and restart JMeter to pick up the changes
Just in case here is how the list should look like:
azure-core-1.13.0.jar
azure-core-amqp-2.0.2.jar
azure-messaging-eventhubs-5.5.0.jar
jackson-annotations-2.11.3.jar
jackson-core-2.11.3.jar
jackson-databind-2.11.3.jar
jackson-dataformat-xml-2.11.3.jar
jackson-datatype-jsr310-2.11.3.jar
jackson-module-jaxb-annotations-2.11.3.jar
jakarta.activation-api-1.2.1.jar
jakarta.xml.bind-api-2.3.2.jar
netty-tcnative-boringssl-static-2.0.35.Final.jar
proton-j-0.33.4.jar
qpid-proton-j-extensions-1.2.3.jar
reactive-streams-1.0.3.jar
reactor-core-3.3.12.RELEASE.jar
slf4j-api-1.7.30.jar
stax2-api-4.2.1.jar
woodstox-core-6.2.1.jar
Also be aware that according to JMeter Best Practices you should always be using the latest version of JMeter so consider upgrading to JMeter 5.4 (or whatever is the latest version available at JMeter Downloads page) as soon as possible.
In my current project we are using aws-lambda to make a rest call to external service and consume the response. Happy path works fine but when it comes to connection-timeout or socket-timeout it is not working as expected. Little more details below
When making a call to external system and if the read-timeout scenario happens (external system connection got established but did not receive any response from the system within 15 sec) the aws lambda keeps waiting for the response till lambda-timeout (25 sec) and returns error.
But I expect the rest-call code invoked within lamda to throw the SocketTimeOutException or related one which is not happening.
Same thing, when I tried using a sample java code (using apache's http-client implementation which is what I have used in lambda) it works perfectly fine and I am getting proper exception thrown.
Initially we tried with jersey implementation for making rest-call and thought this is having issue and changed to http-client implementation, but none of them thrown the exception as it does in sample java code.
Please let me know your suggestions or solutions if faced already.
Below is the code snippet that I use in both lambda as well as sample program for making the rest call. (this whole block is wrapped under try-catch)
HttpPost post = new HttpPost(URL);
RequestJSONObject request = new RequestJSONObject();
//setting required request payload
ObjectMapper mapper = new ObjectMapper();
String jsonStr = mapper.writeValueAsString(request);
post.setEntity(new StringEntity(jsonStr));
post.addHeader("content-type", "application/json");
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(1000)
.setSocketTimeout(3000).build();
CloseableHttpClient httpClient =
HttpClientBuilder.create().setDefaultRequestConfig(config).build();
CloseableHttpResponse response = httpClient.execute(post);
Thanks,
Ganesh Karthik C.
Background
I am working on an application which uses spring-integration to retrieve files via ftp. I was using one of the spring-integration's ftp inbound adapter. However even after my repeated tries, I was not able to get it working. So I started looking though the code and found that under the wraps it uses apache commons net api.
Question
Using apache commons net library, I wrote the code locally in the same way and it was not working. Here is the code -
FTPClient client = new FTPClient();
client.connect("x.x.x.x", 21);
client.enterLocalPassiveMode();
client.login("xxx", "xxx");
FTPFile[] files = client.listFiles("/AMNH");
This returns me 0 rows. This is how the spring-integration executes the call - client.listFiles("/AMNH"). So the list of files returned is 0 and even though I have files at the ftp location, the whole application sits idle.
However, If I run the following code, I am able to retrieve the files. I was wondering what is wrong with the method listFiles when we pass parameters and how do we work around it ? I say this because I don't have the luxury of not executing listFiles(String pathName)
FTPClient client = new FTPClient();
client.connect("x.x.x.x", 21);
client.enterLocalPassiveMode();
client.login("xxx", "xxx");
client.changeWorkingDirectory("/AMNH");
FTPFile[] files = client.listFiles("");
Please, take a look into Reference Manual regarding changeWorkingDirectory. You only need to extend the DefaultFtpSessionFactory and implement postProcessClientAfterConnect() callback.
I was wondering if anyone has seen a demo/example of using the Serilog.Extras.MSOwin package with a web api project or a example/tutorial of using Serilog with a web api project.
Any help greatly appreciated,
Jim
I will take this as question as "How do I used Serilog.Extras.MSOwin?" and given it is currently a rather small library answer here.
This reflects the current library (1.4.102) and is subject to change in the future.
Serilog.Extras.MSOwin provides two things: a Microsoft.Owin.Logging.ILoggerFactory implementation to have OWIN's logging infrastructure write to Serilog (more details about logging in OWIN in this blog post) and Guid identifier (RequestId) for each web request to aid in associating logged events.
The Logging integration is done with the following:
IAppBuilder app = ...;
Serilog.ILogger logger = ...'
app.SetLoggerFactory( new Serilog.Extras.MSOwin.LoggerFactory( logger ) );
The request id functionality needs to be registered in the OWIN pipeline:
IAppBuilder app = ...;
app.UseSerilogRequestContext("RequestId");
You will want to register that very early in the pipeline because any logging occurring before that pipeline step will not have the request id available.
You also need will need to retrieve it from the LogContext using Enrich.FromLogContext() and add that property to what you write to your sinks. For example,
const string DefaultOutputTemplate =
"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} ({RequestId}) {Message}{NewLine}{Exception}";
ILogger logger =
new LoggerConfiguration().Enrich.FromLogContext()
.WriteTo
.RollingFile(
"log.txt",
outputTemplate: DefaultOutputTemplate)
.CreateLogger();
Serilog.Extras.MSOwin was superseded by SerilogWeb.Owin (which has since also been discontinued.)
I am working on a .NET MVC3 C# Application. This application is hosted on our own Server.
Now I want to Send Scheduled Email in my application like daily(at a specific time),Weekly, monthly and so on...
Currently I am using MVCMailer to send Emails in my application.
I tried Fluent Scheduler to send scheduled Emails, but it doesn't works with MVCMailer. It Works fine if I send mails without MVCMailer and for other scheduling jobs.
It gives me a ERROR NULLReferenceException and says HTTPContext cannot be null.
What can I do to solve this problem.
Also suggest me which will be the best way to send E-mails in my applicaton.
Windows Service (Having own server)
Scheduler (Fluent Scheduler)
SQL Scheduled jobs
I am attaching ERROR snapshot:
It could be that MVCMailer depends on an HttpContext, which will not exist on your scheduled threadlocal's.
You could consider scrapping MvcMailer and implementing your own templating solution. Something like RazorEngine (https://github.com/Antaris/RazorEngine), which gives you the full power of Razor without having to run ontop on an Http stack. You could still source your templates from disk so that your designers could modify it.
Then you could mail the results using the standard classes available from .net.
For e.g.:
string template = File.ReadAllText(fileLocation);//"Hello #Model.Name, welcome to RazorEngine!";
string emailBody = Razor.Parse(template, new { Name = "World" });
SmtpClient client = new SmtpClient();
client.Host = "mail.yourserver.com";
MailMessage mm = new MailMessage();
mm.Sender = new MailAddress("foo#bar.com", "Foo Bar");
mm.From = new MailAddress("foo#bar.com", "Foo Bar");
mm.To.Add = new MailAddress("foo#bar.com", "Foo Bar");
mm.Subject = "Test";
mm.Body = emailBody;
mm.IsBodyHtml = true;
client.Send(mm);
Obviously you could clean this all up. But it wouldn't take to much effort to use the above code and create some reusable classes. :)
Since you already have the FluentScheduler code set up, you may as well stick with that I guess. A windows service does also sound appealing, however I think that it's your call to make. If it's a simple mail service you are after I can't think of any reason not to do it via FluentScheduler.
I have created a full example of this available here: https://bitbucket.org/acleancoder/razorengine-email-example/src/dfee804d526ef3cd17fb448970fbbe33f4e4bb79?at=default
You can download the website to run locally here: https://bitbucket.org/acleancoder/razorengine-email-example/downloads
Just make sure to change the Default.aspx.cs file to have your correct mail server details.
Hope this helps.
Since MVC Mailer works best in the HTTP stack (i.e. from controllers), I've found that a very reliable way to accomplish this is by using Windows Task Schedule from a server somewhere. You could even spin up a micro instance on Amazon Web Server.
Use "curl" to call the URL of your controller that does the work and sends the emails.
Just setup a Scheduled Task (or Cron if you want to use *IX) to call "c:\path_to_curl\curl.exe http://yourserver.com/your_controller/your_action".
You could even spin up a *IX server on AWS to make it even cheaper.