public Service createGenericEventService(String name, String version, String event, String referencePayload)
         throws EntityAlreadyExistsException {
      log.info("Creating a new Service '{}-{}' for generic event {}", name, version, event);

      // Check if corresponding Service already exists.
      Service existingService = serviceRepository.findByNameAndVersion(name, version);
      if (existingService != null) {
         log.warn("A Service '{}-{}' is already existing. Throwing an Exception", name, version);
         throw new EntityAlreadyExistsException(
               String.format("Service '%s-%s' is already present in store", name, version));
      }
      // Create new service with GENERIC_EVENT type.
      Service service = new Service();
      service.setName(name);
      service.setVersion(version);
      service.setType(ServiceType.GENERIC_EVENT);
      service.setMetadata(new Metadata());

      // Now create basic crud operations for the resource.
      Operation subscribeOp = new Operation();
      subscribeOp.setName("SUBSCRIBE " + event);
      subscribeOp.setMethod("SUBSCRIBE");

      subscribeOp.setDefaultDelay(defaultAsyncFrequency);
      // Create bindings for Kafka and Websockets.
      Binding kafkaBinding = new Binding(BindingType.KAFKA);
      kafkaBinding.setKeyType("string");
      Binding wsBinding = new Binding(BindingType.WS);
      wsBinding.setMethod("POST");
      subscribeOp.addBinding(BindingType.KAFKA.name(), kafkaBinding);
      subscribeOp.addBinding(BindingType.WS.name(), wsBinding);
      service.addOperation(subscribeOp);

      serviceRepository.save(service);
      log.info("Having created Service '{}' for generic event {}", service.getId(), event);

      // If reference payload is provided, record a first resource.
      if (referencePayload != null) {
         Resource artifact = new Resource();
         artifact.setName(event + "-asyncapi.yaml");
         artifact.setType(ResourceType.ASYNC_API_SPEC);
         artifact.setServiceId(service.getId());
         artifact.setSourceArtifact(event + "-asyncapi.yaml");
         artifact.setContent(buildAsyncAPISpecContent(service, event, referencePayload));
         resourceRepository.save(artifact);

         EventMessage eventMessage = new EventMessage();
         eventMessage.setName("Reference");
         eventMessage.setContent(referencePayload);
         eventMessage.setOperationId(IdBuilder.buildOperationId(service, subscribeOp));
         eventMessage.setMediaType("application/json");
         eventMessageRepository.save(eventMessage);
         log.info("Having created resource '{}' for Service '{}'", artifact.getId(), service.getId());
      }

      // Publish a Service create event before returning.
      publishServiceChangeEvent(service, ChangeType.CREATED);

      return service;
   }
@Test
   void testCreateGenericEventServiceWithReference() {
      Service created = null;
      try {
         created = service.createGenericEventService("Order Service", "2.0", "order",
               "{\"customerId\": \"123456789\",\n \"amount\": 12.5}");
      } catch (Exception e) {
         fail("No exception should be thrown");
      }

      // Check created object.
      assertNotNull(created.getId());

      // Retrieve object by id and assert on what has been persisted.
      Service retrieved = repository.findById(created.getId()).orElse(null);
      assertEquals("Order Service", retrieved.getName());
      assertEquals("2.0", retrieved.getVersion());
      assertEquals(ServiceType.GENERIC_EVENT, retrieved.getType());
      assertEquals(1, retrieved.getOperations().size());

      List<Resource> resources = resourceRepository.findByServiceId(retrieved.getId());
      assertEquals(1, resources.size());

      Resource resource = resources.get(0);
      assertEquals("order-asyncapi.yaml", resource.getName());
      assertEquals(ResourceType.ASYNC_API_SPEC, resource.getType());
      assertNotNull(resource.getContent());
      assertTrue(resource.getContent().contains("payload: {\"customerId\": \"123456789\", \"amount\": 12.5}"));
   }