This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Listener implements MessageListener { | |
public void onMessage(Message m) { | |
try { | |
TextMessage msg = (TextMessage) m; | |
// Show message | |
System.out.printf("[Dequeued message at %s] %s\n", (new Date()).toString(), msg.getText()); | |
} catch (JMSException e) { | |
e.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try (JMSContext jmsContext = factory.createContext() ) { | |
// Create the queue and topic | |
Queue queue = jmsContext.createQueue("QUEUE_NAME"); | |
// set Message Listener | |
JMSConsumer consumer = jmsContext.createConsumer(queue); | |
// Listener implements MessageListener. | |
consumer.setMessageListener(new Listener()); | |
System.out.println("Receiver is ready, waiting for messages..."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try (JMSContext jmsContext = factory.createContext() ) { | |
// Create the queue and topic | |
Queue queue = jmsContext.createQueue("QUEUE_NAME"); | |
// Create the JMS message producer | |
JMSProducer producer = jmsContext.createProducer(); | |
// Create textmessage | |
TextMessage msg = jmsContext.createTextMessage(String.format("message sent at %s", (new Date()).toString())); | |
// send the message to the queue | |
producer.send(queue, msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.microsoft.azure.servicebus.jms.ServiceBusJmsConnectionFactory; | |
import com.microsoft.azure.servicebus.jms.ServiceBusJmsConnectionFactorySettings; | |
... | |
ServiceBusJmsConnectionFactorySettings connectionFactorySettings = new ServiceBusJmsConnectionFactorySettings(); | |
connectionFactorySettings.setConnectionIdleTimeoutMS(20000); | |
ConnectionFactory factory = new ServiceBusJmsConnectionFactory("CONNECTION_STRING", connectionFactorySettings); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- for Cloud Event --> | |
<dependency> | |
<groupId>io.cloudevents</groupId> | |
<artifactId>cloudevents-http-restful-ws</artifactId> | |
<version>2.0.0-milestone3</version> | |
</dependency> | |
<dependency> | |
<groupId>io.cloudevents</groupId> | |
<artifactId>cloudevents-json-jackson</artifactId> | |
<version>2.0.0-milestone3</version> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>(); | |
headers.add("aeg-sas-key", AEG_KEY); | |
Response response = ClientBuilder.newClient().target(AEG_ENDPOINT) | |
.path("/api/events") | |
.queryParam("api-version", "2018-01-01") | |
.request("application/cloudevents+json") | |
.headers(headers) | |
.post(Entity.entity(serialized, "application/cloudevents+json")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EventFormat format =EventFormatProvider | |
.getInstance() | |
.resolveFormat(JsonFormat.CONTENT_TYPE); | |
byte[] serialized = format.serialize(ce); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JsonObject jsonObject = Json.createObjectBuilder() | |
.add("message", "Using CloudEvents.io API to send CloudEvents!!") | |
.build(); | |
CloudEvent ce = CloudEventBuilder.v1() | |
.withId("A234-1234-1234") | |
.withType("io.logico-jp.ExampleEventType") | |
.withSource(URI.create("io/logico-jp/source")) | |
.withTime(OffsetDateTime.now(ZoneId.ofOffset("UTC", ZoneOffset.UTC))) | |
.withDataContentType(MediaType.APPLICATION_JSON) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- for CloudEvents API --> | |
<dependency> | |
<groupId>io.cloudevents</groupId> | |
<artifactId>cloudevents-http-restful-ws</artifactId> | |
<version>2.0.0-milestone3</version> | |
</dependency> | |
<dependency> | |
<groupId>io.cloudevents</groupId> | |
<artifactId>cloudevents-json-jackson</artifactId> | |
<version>2.0.0-milestone3</version> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Path("/updates") | |
@POST | |
public Response receiveEvent(Optional<JsonObject> obj) { | |
if(obj.isEmpty()) return Response.noContent().status(Response.Status.OK).build(); | |
EventFormat format = EventFormatProvider | |
.getInstance() | |
.resolveFormat(JsonFormat.CONTENT_TYPE); | |
CloudEvent ce = format.deserialize(obj.get().toString().getBytes(StandardCharsets.UTF_8)); |
OlderNewer