hi guys, i want to ask related to make a callback ...
# help
g
hi guys, i want to ask related to make a callback to kafka i already tried using
serveEventListeners
for the rest api, but is there any way to achieve with kafka? thankyouu!!
Copy code
{
  "request": {
    "urlPath": "/something-async",
    "method": "POST"
  },
  "response": {
    "status": 200,
    "body": "{ \"result\": \"SUCCESS BRO\" }"
  },
  "serveEventListeners": [
    {
      "name": "webhook",
      "parameters": {
        "method": "POST",
        "url": "<https://reqres.in/api/users>",
        "headers": {
          "Content-Type": "application/json"
        },
        "body": "{\"name\":\"juragan\",\"job\":\"jaga empang\"}"
      }
    }
  ]
}
t
There's nothing readily built to do this right now but you could write your own serve event listener implementation that posts Kafka messages, using the built-in webhook listener for inspiration.
g
im new to wiremock, and this is dummy question can i add import something like this? seems i need this to achieve sending messages to kafka
Copy code
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.TextMessage;
t
I’m not a Kafka expert, but I’d expect you’d want to use the official Kafka Java client in your event listener rather than JMS classes, unless you’re using some kind of JMS to Kafka bridge in your org?
g
yeah i think better using kafka java client, at the end i just do callback on API rest side
thankyou @Tom!!
have a good day
hi @Tom i want to ask another one is there any extensions related to faker? because our team need to have faker in Indonesian locale
t
I was thinking about this the other day as it happens - that we don’t expose Faker’s locale parameter in the extension at the moment. Unfortunately the only immediate way round this is forking the extension, but I’d definitely be happy to accept a PR that added a locale parameter onto the helper.
g
is the faker is in this repo ?
t
We’ve adopted it now, so this one: https://github.com/wiremock/wiremock-faker-extension
g
oh hi @Tom the team are already good with locale
US
but how to integrate into our json mappings? is it on docker compose or with command line i already put the
jar
inside the
extensions
folder is it the right way? because i was tried and somehow it doesnt works
or anyone can help me for this?
l
You will have to add the extension via the
--extensions
parameter. The extensions that are loaded are displayed when WireMock starts up so you will be able to see it when it is loaded. Let me see if I can dig out what you will need
Something like this i think -
--extensions org.wiremock.RandomExtension
You should then see the extension loaded
Copy code
extensions:                   faker-helper,response-template,webhook
g
i already specify it on
docker-compose.yml
but it didnt shoown up
am I missed something? thanks before @Lee Turner
t
Seems the faker extension doesn’t have the service loader file at the moment so you’ll need to add
--extensions org.wiremock.RandomExtension
to your entrypoint
Get rid of the --extensions …Webhook as this is loaded by default now.
g
alright will try now
the result is like this @Tom
Copy code
[+] Running 1/0
 ✔ Container wiremock-local-wiremock-dadit-server-1  Created                                                                                                                                            0.0s 
Attaching to wiremock-dadit-server-1
wiremock-dadit-server-1  | Exception in thread "main" 
wiremock-dadit-server-1  | Exception: java.util.MissingResourceException thrown from the UncaughtExceptionHandler in thread "main"
wiremock-dadit-server-1 exited with code 1
l
Have you tried separating the commands out:
Copy code
entrypoint: [ "/docker-entrypoint.sh", "--verbose" , "--extensions", "org.wiremock.RandomExtension" ]
g
i tried, and then this error comes up somehow the extensions is not loaded right?
Copy code
[+] Running 1/0
 ✔ Container wiremock-local-wiremock-dadit-server-1  Created                                                                                                                                            0.0s 
Attaching to wiremock-dadit-server-1
wiremock-dadit-server-1  | 2024-02-28 11:43:12.699 Verbose logging enabled
wiremock-dadit-server-1  | Exception in thread "main" java.lang.ClassNotFoundException: org.wiremock.RandomExtension
wiremock-dadit-server-1  |      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
wiremock-dadit-server-1  |      at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
wiremock-dadit-server-1  |      at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
wiremock-dadit-server-1  |      at java.base/java.lang.Class.forName0(Native Method)
wiremock-dadit-server-1  |      at java.base/java.lang.Class.forName(Unknown Source)
wiremock-dadit-server-1  |      at com.github.tomakehurst.wiremock.extension.Extensions.loadClass(Extensions.java:222)
wiremock-dadit-server-1  |      at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
wiremock-dadit-server-1  |      at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source)
wiremock-dadit-server-1  |      at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
wiremock-dadit-server-1  |      at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
wiremock-dadit-server-1  |      at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(Unknown Source)
wiremock-dadit-server-1  |      at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Unknown Source)
wiremock-dadit-server-1  |      at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
wiremock-dadit-server-1  |      at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
wiremock-dadit-server-1  |      at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source)
wiremock-dadit-server-1  |      at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)
wiremock-dadit-server-1  |      at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
wiremock-dadit-server-1  |      at java.base/java.util.stream.ReferencePipeline.forEach(Unknown Source)
wiremock-dadit-server-1  |      at com.github.tomakehurst.wiremock.extension.Extensions.load(Extensions.java:80)
wiremock-dadit-server-1  |      at com.github.tomakehurst.wiremock.core.WireMockApp.<init>(WireMockApp.java:94)
wiremock-dadit-server-1  |      at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:71)
wiremock-dadit-server-1  |      at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:71)
wiremock-dadit-server-1  |      at wiremock.Run.main(Run.java:23)
l
Are you mapping the extensions directory?
t
Suggests that somehow the faker JAR file hasn’t been added to the classpath
g
yap already mapped
Copy code
.
├── __files
├── docker-compose.yml
├── docker-entrypoint.sh
├── krdv-mocking
│   ├── __files
│   │   └── pefindo
│   │       ├── callback-pefindo-status_id_2.json
│   │       ├── callback-pefindo-status_id_5.json
│   │       └── pefindo-response.json
│   ├── extensions
│   │   ├── wiremock-body-transformer-1.1.3.jar
│   │   ├── wiremock-faker-extension-0.1.1.jar
│   │   ├── wiremock-faker-extension-standalone-0.1.1.jar
│   │   └── wiremock-grpc-extension-standalone-0.5.0.jar
│   └── mappings
│       └── pefindo.json
├── mappings
└── pom.xml
and it already sent also to the docker volumes
t
Your entrypoint script seems to be running Docker in Docker. How about just using the default one in the wiremock image and passing the extra CLI parameters to it?
g
so just remove the
docker-entrypoint.sh
and try again yes?
t
Yep, think that should do it
g
yup sorted it out but the another issue is come i managed using this command
Copy code
docker run -it --rm \
  -p 8080:8080 \
  --name wiremock \
  -v $PWD/extensions:/var/wiremock/extensions \
  -v $PWD/__files:/var/wiremock/__files \
  -v $PWD/mappings:/var/wiremock/mappings \
  wiremock/wiremock \
    --extensions org.wiremock.RandomExtension, org.wiremock.RandomHelper
but when i hit the endpoint it shows
Copy code
2024-02-28 12:10:45.205 No response could be served as there are no stub mappings in this WireMock instance.
i checked on the docker files
the files are there
the extension is loaded but other files not found 😞
either if i run with standalone jar with this command it become java error
Copy code
java -jar wiremock-standalone-3.4.1.jar --port 8080 --extensions org.wiremock.RandomExtension, org.wiremock.RandomHelper
done solved guys thankyou! just make the folder mapping different
Copy code
docker run -it --rm \
  -p 8080:8080 \
  --name wiremock \
  -v $PWD/extensions:/var/wiremock/extensions \
  -v $PWD/__files:/home/wiremock/__files \
  -v $PWD/mappings:/home/wiremock/mappings \
  wiremock/wiremock \
    --extensions org.wiremock.RandomExtension, org.wiremock.RandomHelper
l
Good stuff. Glad it is all sorted
We have now pushed a new release of the faker extension with a service loader file - https://wiremock-community.slack.com/archives/C04JE0AFE76/p1709140034983969
g
okaay thankyiouu @Lee Turner