Replace CRLF by LF

... because LF is now commonly used as newline code.

Also some files in the samples directory has 755 permission but x bit
is not needed. This removes the unnecessary bit as well.

Change-Id: I6119e508481c9c0f8a5c1c2c40bb2e3a788abd3c
This commit is contained in:
Takashi Kajinami 2024-01-27 12:39:06 +09:00
parent f246df12e5
commit cdb55499f6
11 changed files with 369 additions and 369 deletions

View File

@ -1,43 +1,43 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.openstack.zaqar.sample;
import java.io.StringReader;
import javax.json.Json;
import javax.json.JsonObject;
import javax.websocket.Decoder;
import javax.websocket.EndpointConfig;
public final class JsonDecoder implements Decoder.Text<JsonObject> {
@Override
public JsonObject decode(final String s) {
return Json.createReader(new StringReader(s)).readObject();
}
@Override
public void destroy() {
}
@Override
public void init(final EndpointConfig config) {
}
@Override
public boolean willDecode(final String s) {
return true;
}
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.openstack.zaqar.sample;
import java.io.StringReader;
import javax.json.Json;
import javax.json.JsonObject;
import javax.websocket.Decoder;
import javax.websocket.EndpointConfig;
public final class JsonDecoder implements Decoder.Text<JsonObject> {
@Override
public JsonObject decode(final String s) {
return Json.createReader(new StringReader(s)).readObject();
}
@Override
public void destroy() {
}
@Override
public void init(final EndpointConfig config) {
}
@Override
public boolean willDecode(final String s) {
return true;
}
}

View File

@ -1,57 +1,57 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
import static java.lang.System.out;
import java.io.IOException;
import javax.json.JsonObject;
import javax.websocket.ClientEndpoint;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.RemoteEndpoint;
import javax.websocket.Session;
@ClientEndpoint(decoders = JsonDecoder.class)
public final class SampleZaqarEndpoint {
@OnMessage
public void onMessage(final JsonObject msg) {
if (msg.getJsonObject("body").getJsonArray("messages") != null)
out.println(msg.getJsonObject("body").getJsonArray("messages")
.getJsonObject(0).getString("body"));
}
@OnOpen
public void onOpen(final Session sess) throws IOException {
final RemoteEndpoint.Basic remote = sess.getBasicRemote();
final String authenticateMsg = "{\"action\":\"authenticate\","
+ "\"headers\":{\"X-Auth-Token\":"
+ "\"8444886dd9b04a1b87ddb502b508261c\",\"X-Project-ID\":"
+ "\"7530fad032ca431e9dc8ed4a5de5d99c\"}}"; // refer to bug
// #1553398
remote.sendText(authenticateMsg);
final String claimCreateMsg = "{\"action\":\"claim_create\",\"body\":"
+ "{\"queue_name\":\"SampleQueue\"},\"headers\":{\"Client-ID\":"
+ "\"355186cd-d1e8-4108-a3ac-a2183697232a\",\"X-Project-ID\":"
+ "\"7530fad032ca431e9dc8ed4a5de5d99c\"}}";
remote.sendText(claimCreateMsg);
}
}
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
import static java.lang.System.out;
import java.io.IOException;
import javax.json.JsonObject;
import javax.websocket.ClientEndpoint;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.RemoteEndpoint;
import javax.websocket.Session;
@ClientEndpoint(decoders = JsonDecoder.class)
public final class SampleZaqarEndpoint {
@OnMessage
public void onMessage(final JsonObject msg) {
if (msg.getJsonObject("body").getJsonArray("messages") != null)
out.println(msg.getJsonObject("body").getJsonArray("messages")
.getJsonObject(0).getString("body"));
}
@OnOpen
public void onOpen(final Session sess) throws IOException {
final RemoteEndpoint.Basic remote = sess.getBasicRemote();
final String authenticateMsg = "{\"action\":\"authenticate\","
+ "\"headers\":{\"X-Auth-Token\":"
+ "\"8444886dd9b04a1b87ddb502b508261c\",\"X-Project-ID\":"
+ "\"7530fad032ca431e9dc8ed4a5de5d99c\"}}"; // refer to bug
// #1553398
remote.sendText(authenticateMsg);
final String claimCreateMsg = "{\"action\":\"claim_create\",\"body\":"
+ "{\"queue_name\":\"SampleQueue\"},\"headers\":{\"Client-ID\":"
+ "\"355186cd-d1e8-4108-a3ac-a2183697232a\",\"X-Project-ID\":"
+ "\"7530fad032ca431e9dc8ed4a5de5d99c\"}}";
remote.sendText(claimCreateMsg);
}
}

View File

@ -1,45 +1,45 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
import java.io.IOException;
import javax.websocket.ClientEndpoint;
import javax.websocket.OnOpen;
import javax.websocket.RemoteEndpoint;
import javax.websocket.Session;
@ClientEndpoint
public final class SampleZaqarEndpoint {
@OnOpen
public void onOpen(final Session sess) throws IOException {
final RemoteEndpoint.Basic remote = sess.getBasicRemote();
final String authenticateMsg = "{\"action\":\"authenticate\","
+ "\"headers\":{\"X-Auth-Token\":"
+ "\"8444886dd9b04a1b87ddb502b508261c\",\"X-Project-ID\":"
+ "\"7530fad032ca431e9dc8ed4a5de5d99c\"}}"; // refer to bug
// #1553398
remote.sendText(authenticateMsg);
final String messagePostMsg = "{\"action\":\"message_post\",\"body\":"
+ "{\"messages\":[{\"body\":\"Zaqar Sample\"}],\"queue_name\":"
+ "\"SampleQueue\"},\"headers\":{\"Client-ID\":"
+ "\"355186cd-d1e8-4108-a3ac-a2183697232a\",\"X-Project-ID\":"
+ "\"7530fad032ca431e9dc8ed4a5de5d99c\"}}";
remote.sendText(messagePostMsg);
}
}
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
import java.io.IOException;
import javax.websocket.ClientEndpoint;
import javax.websocket.OnOpen;
import javax.websocket.RemoteEndpoint;
import javax.websocket.Session;
@ClientEndpoint
public final class SampleZaqarEndpoint {
@OnOpen
public void onOpen(final Session sess) throws IOException {
final RemoteEndpoint.Basic remote = sess.getBasicRemote();
final String authenticateMsg = "{\"action\":\"authenticate\","
+ "\"headers\":{\"X-Auth-Token\":"
+ "\"8444886dd9b04a1b87ddb502b508261c\",\"X-Project-ID\":"
+ "\"7530fad032ca431e9dc8ed4a5de5d99c\"}}"; // refer to bug
// #1553398
remote.sendText(authenticateMsg);
final String messagePostMsg = "{\"action\":\"message_post\",\"body\":"
+ "{\"messages\":[{\"body\":\"Zaqar Sample\"}],\"queue_name\":"
+ "\"SampleQueue\"},\"headers\":{\"Client-ID\":"
+ "\"355186cd-d1e8-4108-a3ac-a2183697232a\",\"X-Project-ID\":"
+ "\"7530fad032ca431e9dc8ed4a5de5d99c\"}}";
remote.sendText(messagePostMsg);
}
}

64
samples/javascript/receive_message/zaqar_sample.js Executable file → Normal file
View File

@ -1,32 +1,32 @@
/*
* Licensed under the Apache License, Version 2.0 (the 'License'); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
const ws = new WebSocket('ws://localhost:9000');
ws.onmessage = (e) => {
const msg = JSON.parse(e.data);
if (msg.body.messages)
console.log(msg.body.messages[0].body);
};
ws.onopen = () => {
ws.send('{"action": "authenticate", "headers": {"X-Auth-Token": \
"8444886dd9b04a1b87ddb502b508261c", "X-Project-ID": \
"7530fad032ca431e9dc8ed4a5de5d99c"}}'); // refer to bug #1553398
ws.send('{"action": "claim_create", "body": {"queue_name": "SampleQueue"}, \
"headers": {"Client-ID": "355186cd-d1e8-4108-a3ac-a2183697232a", \
"X-Project-ID": "7530fad032ca431e9dc8ed4a5de5d99c"}}');
};
/*
* Licensed under the Apache License, Version 2.0 (the 'License'); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
const ws = new WebSocket('ws://localhost:9000');
ws.onmessage = (e) => {
const msg = JSON.parse(e.data);
if (msg.body.messages)
console.log(msg.body.messages[0].body);
};
ws.onopen = () => {
ws.send('{"action": "authenticate", "headers": {"X-Auth-Token": \
"8444886dd9b04a1b87ddb502b508261c", "X-Project-ID": \
"7530fad032ca431e9dc8ed4a5de5d99c"}}'); // refer to bug #1553398
ws.send('{"action": "claim_create", "body": {"queue_name": "SampleQueue"}, \
"headers": {"Client-ID": "355186cd-d1e8-4108-a3ac-a2183697232a", \
"X-Project-ID": "7530fad032ca431e9dc8ed4a5de5d99c"}}');
};

50
samples/javascript/send_message/zaqar_sample.js Executable file → Normal file
View File

@ -1,25 +1,25 @@
/*
* Licensed under the Apache License, Version 2.0 (the 'License'); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
const ws = new WebSocket('ws://localhost:9000');
ws.onopen = () => {
ws.send('{"action": "authenticate", "headers": {"X-Auth-Token": \
"8444886dd9b04a1b87ddb502b508261c", "X-Project-ID": \
"7530fad032ca431e9dc8ed4a5de5d99c"}}'); // refer to bug #1553398
ws.send('{"action": "message_post", "body": {"messages": [{"body": \
"Zaqar Sample"}], "queue_name": "SampleQueue"}, "headers": \
{"Client-ID": "355186cd-d1e8-4108-a3ac-a2183697232a", "X-Project-ID": \
"7530fad032ca431e9dc8ed4a5de5d99c"}}');
};
/*
* Licensed under the Apache License, Version 2.0 (the 'License'); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
const ws = new WebSocket('ws://localhost:9000');
ws.onopen = () => {
ws.send('{"action": "authenticate", "headers": {"X-Auth-Token": \
"8444886dd9b04a1b87ddb502b508261c", "X-Project-ID": \
"7530fad032ca431e9dc8ed4a5de5d99c"}}'); // refer to bug #1553398
ws.send('{"action": "message_post", "body": {"messages": [{"body": \
"Zaqar Sample"}], "queue_name": "SampleQueue"}, "headers": \
{"Client-ID": "355186cd-d1e8-4108-a3ac-a2183697232a", "X-Project-ID": \
"7530fad032ca431e9dc8ed4a5de5d99c"}}');
};

110
samples/jaxrs/receive_message/SampleZaqarServlet.java Executable file → Normal file
View File

@ -1,55 +1,55 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
import java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
@SuppressWarnings("serial")
@WebServlet(name = "SampleServlet", value = "/")
public final class SampleZaqarServlet extends HttpServlet {
@Override
protected void doGet(final HttpServletRequest req,
final HttpServletResponse resp) throws IOException {
final Client client = ClientBuilder.newClient();
final MultivaluedMap<String, Object> headers =
new MultivaluedHashMap<String, Object>();
headers.putSingle("Client-ID", "355186cd-d1e8-4108-a3ac-a2183697232a");
headers.putSingle("X-Auth-Token", "8444886dd9b04a1b87ddb502b508261c");
headers.putSingle("X-Project-Id", "7530fad032ca431e9dc8ed4a5de5d99c");
final Response res = client
.target("http://localhost:8888/v2/queues/SampleQueue/claims")
.request().headers(headers).post(Entity.json(""));
resp.getWriter().println(res.readEntity(String.class));
client.close();
}
}
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
import java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
@SuppressWarnings("serial")
@WebServlet(name = "SampleServlet", value = "/")
public final class SampleZaqarServlet extends HttpServlet {
@Override
protected void doGet(final HttpServletRequest req,
final HttpServletResponse resp) throws IOException {
final Client client = ClientBuilder.newClient();
final MultivaluedMap<String, Object> headers =
new MultivaluedHashMap<String, Object>();
headers.putSingle("Client-ID", "355186cd-d1e8-4108-a3ac-a2183697232a");
headers.putSingle("X-Auth-Token", "8444886dd9b04a1b87ddb502b508261c");
headers.putSingle("X-Project-Id", "7530fad032ca431e9dc8ed4a5de5d99c");
final Response res = client
.target("http://localhost:8888/v2/queues/SampleQueue/claims")
.request().headers(headers).post(Entity.json(""));
resp.getWriter().println(res.readEntity(String.class));
client.close();
}
}

104
samples/jaxrs/send_message/SampleZaqarServlet.java Executable file → Normal file
View File

@ -1,52 +1,52 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
@SuppressWarnings("serial")
@WebServlet(name = "SampleZaqarServlet", value = "/")
public final class SampleZaqarServlet extends HttpServlet {
@Override
protected void doGet(final HttpServletRequest req,
final HttpServletResponse resp) {
final Client client = ClientBuilder.newClient();
final MultivaluedMap<String, Object> headers =
new MultivaluedHashMap<String, Object>();
headers.putSingle("Client-ID", "355186cd-d1e8-4108-a3ac-a2183697232a");
headers.putSingle("X-Auth-Token", "8444886dd9b04a1b87ddb502b508261c");
headers.putSingle("X-Project-Id", "7530fad032ca431e9dc8ed4a5de5d99c");
client.target("http://localhost:8888/v2/queues/SampleQueue/messages")
.request(MediaType.APPLICATION_JSON_TYPE).headers(headers)
.post(Entity
.json("{\"messages\":[{\"body\":\"Zaqar Sample\"}]}"));
client.close();
}
}
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
@SuppressWarnings("serial")
@WebServlet(name = "SampleZaqarServlet", value = "/")
public final class SampleZaqarServlet extends HttpServlet {
@Override
protected void doGet(final HttpServletRequest req,
final HttpServletResponse resp) {
final Client client = ClientBuilder.newClient();
final MultivaluedMap<String, Object> headers =
new MultivaluedHashMap<String, Object>();
headers.putSingle("Client-ID", "355186cd-d1e8-4108-a3ac-a2183697232a");
headers.putSingle("X-Auth-Token", "8444886dd9b04a1b87ddb502b508261c");
headers.putSingle("X-Project-Id", "7530fad032ca431e9dc8ed4a5de5d99c");
client.target("http://localhost:8888/v2/queues/SampleQueue/messages")
.request(MediaType.APPLICATION_JSON_TYPE).headers(headers)
.post(Entity
.json("{\"messages\":[{\"body\":\"Zaqar Sample\"}]}"));
client.close();
}
}

68
samples/nodejs/receive_message/zaqar_sample.js Executable file → Normal file
View File

@ -1,34 +1,34 @@
/*
* Licensed under the Apache License, Version 2.0 (the 'License'); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
const WebSocket = require('ws');
const ws = new WebSocket('ws://localhost:9000');
ws.on('message', (data, flags) => {
const msg = JSON.parse(data);
if (msg.body.messages)
console.log(msg.body.messages[0].body);
});
ws.on('open', () => {
ws.send('{"action": "authenticate", "headers": {"X-Auth-Token": \
"8444886dd9b04a1b87ddb502b508261c", "X-Project-ID": \
"7530fad032ca431e9dc8ed4a5de5d99c"}}'); // refer to bug #1553398
ws.send('{"action": "claim_create", "body": {"queue_name": "SampleQueue"}, \
"headers": {"Client-ID": "355186cd-d1e8-4108-a3ac-a2183697232a", \
"X-Project-ID": "7530fad032ca431e9dc8ed4a5de5d99c"}}');
});
/*
* Licensed under the Apache License, Version 2.0 (the 'License'); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
const WebSocket = require('ws');
const ws = new WebSocket('ws://localhost:9000');
ws.on('message', (data, flags) => {
const msg = JSON.parse(data);
if (msg.body.messages)
console.log(msg.body.messages[0].body);
});
ws.on('open', () => {
ws.send('{"action": "authenticate", "headers": {"X-Auth-Token": \
"8444886dd9b04a1b87ddb502b508261c", "X-Project-ID": \
"7530fad032ca431e9dc8ed4a5de5d99c"}}'); // refer to bug #1553398
ws.send('{"action": "claim_create", "body": {"queue_name": "SampleQueue"}, \
"headers": {"Client-ID": "355186cd-d1e8-4108-a3ac-a2183697232a", \
"X-Project-ID": "7530fad032ca431e9dc8ed4a5de5d99c"}}');
});

54
samples/nodejs/send_message/zaqar_sample.js Executable file → Normal file
View File

@ -1,27 +1,27 @@
/*
* Licensed under the Apache License, Version 2.0 (the 'License'); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
const WebSocket = require('ws');
const ws = new WebSocket('ws://localhost:9000');
ws.on('open', () => {
ws.send('{"action": "authenticate", "headers": {"X-Auth-Token": \
"8444886dd9b04a1b87ddb502b508261c", "X-Project-ID": \
"7530fad032ca431e9dc8ed4a5de5d99c"}}'); // refer to bug #1553398
ws.send('{"action": "message_post", "body": {"messages": [{"body": \
"Zaqar Sample"}], "queue_name": "SampleQueue"}, "headers": \
{"Client-ID": "355186cd-d1e8-4108-a3ac-a2183697232a", "X-Project-ID": \
"7530fad032ca431e9dc8ed4a5de5d99c"}}');
});
/*
* Licensed under the Apache License, Version 2.0 (the 'License'); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
const WebSocket = require('ws');
const ws = new WebSocket('ws://localhost:9000');
ws.on('open', () => {
ws.send('{"action": "authenticate", "headers": {"X-Auth-Token": \
"8444886dd9b04a1b87ddb502b508261c", "X-Project-ID": \
"7530fad032ca431e9dc8ed4a5de5d99c"}}'); // refer to bug #1553398
ws.send('{"action": "message_post", "body": {"messages": [{"body": \
"Zaqar Sample"}], "queue_name": "SampleQueue"}, "headers": \
{"Client-ID": "355186cd-d1e8-4108-a3ac-a2183697232a", "X-Project-ID": \
"7530fad032ca431e9dc8ed4a5de5d99c"}}');
});

View File

View File