Search in sources :

Example 1 with PutEventsRequest

use of software.amazon.awssdk.services.personalizeevents.model.PutEventsRequest in project aws-doc-sdk-examples by awsdocs.

the class AmazonPersonalizeRecommender method putEvent.

public void putEvent(UserEvent e) {
    try {
        Event event = Event.builder().eventId(UUID.randomUUID().toString()).eventType(e.event).itemId(e.itemId).sentAt(Instant.ofEpochMilli(System.currentTimeMillis() + 10 * 60 * 1000)).build();
        PutEventsRequest putEventsRequest = PutEventsRequest.builder().trackingId(trackingId).userId(e.getUserId()).sessionId("temp").eventList(event).build();
        personalizeEventsClient.putEvents(putEventsRequest);
        System.out.println("Event sent: " + e);
    } catch (AwsServiceException ex) {
        System.err.println(ex.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) Event(software.amazon.awssdk.services.personalizeevents.model.Event) PutEventsRequest(software.amazon.awssdk.services.personalizeevents.model.PutEventsRequest)

Example 2 with PutEventsRequest

use of software.amazon.awssdk.services.personalizeevents.model.PutEventsRequest in project aws-doc-sdk-examples by awsdocs.

the class PutEvents method putEvents.

// snippet-start:[personalize.java2.put_events.main]
public static int putEvents(PersonalizeEventsClient personalizeEventsClient, String trackingId, String userId, String itemId, String sessionId) {
    int responseCode = 0;
    try {
        // Build an event and a putEvents request with only the required information for a minimal schema.
        // Schema columns for this example would be itemId, userId, and timestamp.
        Event event = Event.builder().sentAt(Instant.ofEpochMilli(System.currentTimeMillis() + 10 * 60 * 1000)).itemId(itemId).eventType("typePlaceholder").build();
        PutEventsRequest putEventsRequest = PutEventsRequest.builder().trackingId(trackingId).userId(userId).sessionId(sessionId).eventList(event).build();
        responseCode = personalizeEventsClient.putEvents(putEventsRequest).sdkHttpResponse().statusCode();
        System.out.println("Response code: " + responseCode);
        return responseCode;
    } catch (PersonalizeEventsException e) {
        System.out.println(e.awsErrorDetails().errorMessage());
    }
    return responseCode;
}
Also used : PersonalizeEventsException(software.amazon.awssdk.services.personalizeevents.model.PersonalizeEventsException) Event(software.amazon.awssdk.services.personalizeevents.model.Event) PutEventsRequest(software.amazon.awssdk.services.personalizeevents.model.PutEventsRequest)

Aggregations

Event (software.amazon.awssdk.services.personalizeevents.model.Event)2 PutEventsRequest (software.amazon.awssdk.services.personalizeevents.model.PutEventsRequest)2 AwsServiceException (software.amazon.awssdk.awscore.exception.AwsServiceException)1 PersonalizeEventsException (software.amazon.awssdk.services.personalizeevents.model.PersonalizeEventsException)1