質問編集履歴

1

文言の変更

2018/11/26 00:44

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- プッシュをspring bootで実装しています。
1
+ 外部へのhttps信処理をspring bootで実装しています。
2
2
 
3
3
  通知先が多いと送信処理に時間がかかってしまう為、マルチスレッドを使って処理時間を減らそうと思います。
4
4
 
@@ -8,9 +8,9 @@
8
8
 
9
9
  ・画面から配信データを入力、送信ボタンを押す
10
10
 
11
- ・DBから通知先エンドポイントのリストを取得
11
+ ・DBから通知先データのリストを取得
12
12
 
13
- エンドポイントデータの数だけ送信処理を繰り返す(ここでマルチスレッドを実装)
13
+ 通知先データの数だけ送信処理を繰り返す(ここでマルチスレッドを実装)
14
14
 
15
15
  ・送信処理を行った件数を画面に出力する
16
16
 
@@ -26,7 +26,7 @@
26
26
 
27
27
 
28
28
 
29
- PushApplication.class
29
+ DemoApplication.class
30
30
 
31
31
  ```ここに言語を入力
32
32
 
@@ -34,13 +34,13 @@
34
34
 
35
35
  @EnableAsync
36
36
 
37
- public class PushApplication {
37
+ public class DemoApplication {
38
38
 
39
39
 
40
40
 
41
41
  public static void main(String[] args) {
42
42
 
43
- SpringApplication.run(PushApplication .class, args);
43
+ SpringApplication.run(DemoApplication .class, args);
44
44
 
45
45
  }
46
46
 
@@ -50,17 +50,17 @@
50
50
 
51
51
  ```
52
52
 
53
- ■PushController.class
53
+
54
54
 
55
55
  ```ここに言語を入力
56
56
 
57
57
  @Controller
58
58
 
59
- public class PushController {
59
+ public class DemoController {
60
60
 
61
61
  @Autowired
62
62
 
63
- PushService service;
63
+ DemoService service;
64
64
 
65
65
 
66
66
 
@@ -72,19 +72,17 @@
72
72
 
73
73
  public String subscribe(@ModelAttribute SendForm form, RedirectAttributes redirectAttribute) {
74
74
 
75
- //エンドポイントリストを取得
76
-
77
- List<PushEndpoint> list = this.service.getTargetList();
75
+ List<DemoData> list = this.service.getTargetList();
78
76
 
79
77
  int num = list.size();
80
78
 
81
79
 
82
80
 
83
- this.service.sendPushMessage(list, form);
81
+ this.service.send(list, form);
84
82
 
85
83
 
86
84
 
87
- redirectAttribute.addFlashAttribute("resultMsg", num +"件送信しました。");
85
+ redirectAttribute.addFlashAttribute("num", num);
88
86
 
89
87
  return "redirect:/";
90
88
 
@@ -100,15 +98,15 @@
100
98
 
101
99
  @Service
102
100
 
103
- public class PushService {
101
+ public class DemoService {
104
102
 
105
103
  @Autowired
106
104
 
107
- WebPushConfiguration config;
105
+ DemoConfiguration config;
108
106
 
109
107
 
110
108
 
111
- private static final Log log = LogFactory.getLog(WebPushKanriService.class);
109
+ private static final Log log = LogFactory.getLog(DemoService.class);
112
110
 
113
111
 
114
112
 
@@ -116,11 +114,7 @@
116
114
 
117
115
 
118
116
 
119
- public void sendPushMessage(List<PushEndpoint> list, SendForm form) {
117
+ public void send(List<DemoData> list, SendForm form) {
120
-
121
- Security.addProvider(new BouncyCastleProvider());
122
-
123
-
124
118
 
125
119
  final String PUBLIC_KEY = this.config.getPublicKey();
126
120
 
@@ -138,11 +132,11 @@
138
132
 
139
133
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
140
134
 
141
- PushService pushService = null;
135
+ DemoService demoService = null;
142
136
 
143
137
  try {
144
138
 
145
- pushService = new PushService(PUBLIC_KEY, PRIVATE_KEY, SUBJECT);
139
+ demoService = new DemoService(PUBLIC_KEY, PRIVATE_KEY, SUBJECT);
146
140
 
147
141
  payload = mapper.writeValueAsString(form);
148
142
 
@@ -158,7 +152,7 @@
158
152
 
159
153
  String subscriptionJson = list.get(i).getJson();
160
154
 
161
- this.asyncSendPushMessage(i,subscriptionJson, mapper, payload, pushService);
155
+ this.asyncSend(i,subscriptionJson, mapper, payload, demoService);
162
156
 
163
157
  }
164
158
 
@@ -170,11 +164,7 @@
170
164
 
171
165
  @Async
172
166
 
173
- private void asyncSendPushMessage(int i, String subscriptionJson, ObjectMapper mapper, String payload, PushService pushService) {
167
+ private void asyncSend(int i, String subscriptionJson, ObjectMapper mapper, String payload, DemoService demoService) {
174
-
175
- log.info("service start." + i);
176
-
177
- int statusCode = 0;
178
168
 
179
169
  try {
180
170
 
@@ -182,7 +172,7 @@
182
172
 
183
173
  Notification notification = new Notification(subscription, payload);
184
174
 
185
- HttpResponse httpResponse = pushService.send(notification);
175
+ demoService.send(notification);
186
176
 
187
177
  } catch (Exception e) {
188
178
 
@@ -190,8 +180,6 @@
190
180
 
191
181
  }
192
182
 
193
- log.info("service end." + i);
194
-
195
183
  }
196
184
 
197
185
  }