Skip to content

Commit 817a25d

Browse files
committed
modify: add deadletter example
1 parent 145c821 commit 817a25d

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.meitu</groupId>
88
<artifactId>java-lmstfy-client</artifactId>
9-
<version>1.0-SNAPSHOT</version>
9+
<version>1.0.0</version>
1010
<dependencies>
1111
<dependency>
1212
<groupId>com.squareup.okhttp3</groupId>
@@ -64,5 +64,4 @@
6464
</plugins>
6565
</build>
6666

67-
6867
</project>

src/main/java/com/meitu/platform/lmstfy/client/LmstfyClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ public String publish(String queue, byte[] data, int ttlSecond, short tries, int
107107
default:
108108
throw new LmstfyUnexpectedException(response.getCode());
109109
}
110-
111110
}
112111

113112
/**
@@ -273,7 +272,7 @@ public int respawnDeadLetter(String queue, int limit, int ttlSecond) throws Lmst
273272
.addQueryParameter(QUERY_LIMIT, String.valueOf(limit))
274273
.addQueryParameter(QUERY_TTL, String.valueOf(ttlSecond))
275274
.build();
276-
LmstfyResponse response = doRequest("PUT", url, null);
275+
LmstfyResponse response = doRequest("PUT", url, RequestBody.create(MediaType.parse("text/binary"), new byte[]{}));
277276
switch (response.getCode()) {
278277
case HTTP_OK:
279278
RespawnResponse respawnResponse = response.unmarshalBody(RespawnResponse.class);

src/main/java/com/meitu/platform/lmstfy/example.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.meitu.platform.lmstfy.client.LmstfyClient;
44
import com.meitu.platform.lmstfy.exception.LmstfyException;
55
import com.meitu.platform.lmstfy.exception.LmstfyNotJobException;
6+
import com.meitu.platform.lmstfy.response.DeadLetterResponse;
67

78
/**
89
* Description:
@@ -26,6 +27,8 @@ public static void main(String[] args) {
2627
queueSize();
2728
peekQueue();
2829
peekJob();
30+
peekDeadLetter();
31+
respawnDeadLetter();
2932
}
3033

3134
private static void publish() {
@@ -82,7 +85,6 @@ private static void peekQueue() {
8285
} else {
8386
System.out.println(job.getData());
8487
}
85-
8688
} catch (LmstfyException e) {
8789
System.out.println("Request Lmstfy error, " + e.getMessage());
8890
}
@@ -102,5 +104,23 @@ private static void peekJob() {
102104
}
103105
}
104106

107+
private static void peekDeadLetter() {
108+
try {
109+
DeadLetterResponse deadLetterResponse = client.peekDeadLetter(queue);
110+
System.out.println(deadLetterResponse.getDeadLetterSize());
111+
} catch (LmstfyException e) {
112+
System.out.println("Request Lmstfy error, " + e.getMessage());
113+
}
114+
}
115+
116+
private static void respawnDeadLetter() {
117+
try {
118+
int count = client.respawnDeadLetter(queue, 1, 60);
119+
System.out.println("Respawn deadletter count: " + count);
120+
} catch (LmstfyException e) {
121+
System.out.println("Request Lmstfy error, " + e.getMessage());
122+
}
123+
}
124+
105125

106126
}

0 commit comments

Comments
 (0)