Search code examples
amazon-web-servicesjmeterperformance-testingaws-event-bridge

Put event in Amazaon Event bus using Jmeter


We are introducing an event bridge to communicate btw 2 components and we want to Performance test the inbound event bus. We are using jmeter and want to to do a put event in this inbound event bus. has anyone done something like this ?


Solution

  • Probably the most straightforward way is using AWS SDK for Java from JSR223 Test Elements with Groovy

    Example code can be found at Working with Amazon EventBridge, I'll add it here just in case

    /*
       Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
       SPDX-License-Identifier: Apache-2.0
    */
    
    package com.example.eventbridge;
    
    import software.amazon.awssdk.regions.Region;
    import software.amazon.awssdk.services.eventbridge.EventBridgeClient;
    import software.amazon.awssdk.services.eventbridge.model.EventBridgeException;
    import software.amazon.awssdk.services.eventbridge.model.PutEventsRequest;
    import software.amazon.awssdk.services.eventbridge.model.PutEventsRequestEntry;
    import software.amazon.awssdk.services.eventbridge.model.PutEventsResponse;
    import software.amazon.awssdk.services.eventbridge.model.PutEventsResultEntry;
    import java.util.ArrayList;
    import java.util.List;
    /**
     * To run this Java V2 code example, ensure that you have setup your development environment, including your credentials.
     *
     * For information, see this documentation topic:
     *
     * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
     */
    public class PutEvents {
    
        public static void main(String[] args) {
    
            final String USAGE =
                    "To run this example, supply two resources, identified by Amazon Resource Name (ARN), which the event primarily concerns. " +
                            "Any number, including zero, may be present. \n" +
                            "For example: PutEvents <resourceArn> <resourceArn2>\n";
    
            if (args.length != 2) {
                System.out.println(USAGE);
                System.exit(1);
            }
    
            String resourceArn = args[0];
            String resourceArn2 = args[1];
    
            Region region = Region.US_WEST_2;
            EventBridgeClient eventBrClient = EventBridgeClient.builder()
                    .region(region)
                    .build();
    
            putEBEvents(eventBrClient, resourceArn, resourceArn2);
            eventBrClient.close();
        }
    
        public static void putEBEvents(EventBridgeClient eventBrClient, String resourceArn, String resourceArn2 ) {
    
            try {
                // Populate a List with the resource ARN values
                List<String> resources = new ArrayList<String>();
                resources.add(resourceArn);
                resources.add(resourceArn2);
    
                PutEventsRequestEntry reqEntry = PutEventsRequestEntry.builder()
                        .resources(resources)
                        .source("com.mycompany.myapp")
                        .detailType("myDetailType")
                        .detail("{ \"key1\": \"value1\", \"key2\": \"value2\" }")
                        .build();
    
                // Add the PutEventsRequestEntry to a list
                List<PutEventsRequestEntry> list = new ArrayList<PutEventsRequestEntry>();
                list.add(reqEntry);
    
                PutEventsRequest eventsRequest = PutEventsRequest.builder()
                        .entries(reqEntry)
                        .build();
    
                PutEventsResponse result = eventBrClient.putEvents(eventsRequest);
    
                for (PutEventsResultEntry resultEntry : result.entries()) {
                    if (resultEntry.eventId() != null) {
                        System.out.println("Event Id: " + resultEntry.eventId());
                    } else {
                        System.out.println("Injection failed with Error Code: " + resultEntry.errorCode());
                    }
                }
    
            } catch (EventBridgeException e) {
    
                System.err.println(e.awsErrorDetails().errorMessage());
                System.exit(1);
            }
        }
    }