Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
feat: add new endpoint for emitting raw events (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
ex0b1t authored Dec 11, 2022
1 parent 44e173b commit b883ae5
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
# In each subsection folders are ordered first by depth, then alphabetically.
# This should make it easy to add new rules without breaking existing ones.

* @backbase/backend-leadership @backbase/gromit
* @backbase/gromit
.github/ @backbase/backend-leadership
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ Event emitter allows you to produce events using REST to the underlying message

Event emitter allows you to produce events using REST.

### Raw Event

```shell
curl --location --request POST 'http://localhost:8079/events/raw' \
--header 'Content-Type: application/json' \
--data-raw '{
"destination": "Backbase.engagement.ProvisionItem",
"eventType": "com.backbase.engagement.provisioning.messaging.dto.ProvisionItemCommand",
"body": {
"provisionedItem": {
"itemUuid": "fdc0db99-8201-402e-b8f4-05fe154d44ba",
"itemType": ""
},
"packageUuid": "86d994da-8907-494e-b579-4bc59cfa08e4",
"destination": "",
"override": true
}
}'
```

### Event Spec

```shell
curl --location --request POST 'http://localhost:8079/events/com.backbase.dbs.messages.pandp.event.spec.v4.MessageDeliveredEvent' \
--header 'Content-Type: application/json' \
Expand Down Expand Up @@ -135,7 +157,7 @@ DELETE /events
First off, thanks for taking the time to contribute! Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make will benefit everybody else and are **greatly appreciated**.

Please adhere to this project's [code of conduct](CODE_OF_CONDUCT.md). For detailed instructions on repo organization, linting, testing, and other
steps see our [contributing guidelines](../../../backbase/event-emitter/CONTRIBUTING.md)
steps see our [contributing guidelines](CONTRIBUTING.md)

#### Contributors

Expand Down
8 changes: 5 additions & 3 deletions application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
spring.activemq.broker-url: tcp://localhost:61616
spring.activemq.user: admin
spring.activemq.password: admin
spring:
activemq:
broker-url: tcp://localhost:61616
user: admin
password: admin

backbase:
event-emitter:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.backbase.eo.testing.events.emitter;

import com.backbase.buildingblocks.backend.communication.context.OriginatorContext;
import com.backbase.buildingblocks.backend.communication.event.EnvelopedEvent;
import com.backbase.buildingblocks.backend.communication.event.scs.EventMessageProcessor;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
* {@link RawEmittingController}
* <br>
* {@code com.backbase.eo.testing.events.emitter.RawEmittingController}
* <br>
*
* @author Jaco Botha
* @since 02 December 2022
*/
@Slf4j
@RestController
@RequiredArgsConstructor
public class RawEmittingController {

@Autowired
private StreamBridge bridge;

@Autowired(required = false)
private List<EventMessageProcessor> eventMessageProcessors = Collections.emptyList();

@PostMapping(
path = "/events/raw",
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
public ResponseEntity<Void> emitEvent(@RequestBody RawEventPayload payload) {

OriginatorContext originatorContext = new OriginatorContext();
originatorContext.setRequestUuid(payload.getRequestId());
originatorContext.setCreationTime(payload.getCreationTime());

EnvelopedEvent envelopedEvent = new EnvelopedEvent();
envelopedEvent.setOriginatorContext(originatorContext);
envelopedEvent.setEvent(payload.getBody());

MessageBuilder eventMessageBuilder = MessageBuilder.withPayload(payload.getBody()).setHeader("bbEventType", payload.getEventType());
this.eventMessageProcessors.forEach((processor) -> {
processor.prepareEventMessage(eventMessageBuilder, envelopedEvent);
});
Message message = eventMessageBuilder.build();
log.debug("Event emitted: {}", message.getPayload());

this.bridge.send(payload.getDestination(), message);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@Data
static class RawEventPayload {

private String destination;
private String eventType;
private String requestId = UUID.randomUUID().toString();
private long creationTime = Instant.EPOCH.toEpochMilli();
private Map<String, Object> body;
}
}
5 changes: 2 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ backbase:
security:
public:
paths:
- /events
- /events/*
- /mass-emit/*
- /events/**
- /mass-emit/**

spring:
application:
Expand Down

0 comments on commit b883ae5

Please sign in to comment.